storybook-builder-rsbuild 1.0.2 → 1.0.3

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.
Files changed (3) hide show
  1. package/dist/index.js +212 -30
  2. package/dist/index.mjs +179 -15
  3. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -102,6 +102,41 @@ var require_pretty_hrtime = __commonJS({
102
102
  }
103
103
  });
104
104
 
105
+ // ../../node_modules/.pnpm/common-path-prefix@3.0.0/node_modules/common-path-prefix/index.js
106
+ var require_common_path_prefix = __commonJS({
107
+ "../../node_modules/.pnpm/common-path-prefix@3.0.0/node_modules/common-path-prefix/index.js"(exports, module2) {
108
+ "use strict";
109
+ var { sep: DEFAULT_SEPARATOR } = require("path");
110
+ var determineSeparator = (paths) => {
111
+ for (const path6 of paths) {
112
+ const match = /(\/|\\)/.exec(path6);
113
+ if (match !== null)
114
+ return match[0];
115
+ }
116
+ return DEFAULT_SEPARATOR;
117
+ };
118
+ module2.exports = function commonPathPrefix2(paths, sep = determineSeparator(paths)) {
119
+ const [first = "", ...remaining] = paths;
120
+ if (first === "" || remaining.length === 0)
121
+ return "";
122
+ const parts = first.split(sep);
123
+ let endOfPrefix = parts.length;
124
+ for (const path6 of remaining) {
125
+ const compare = path6.split(sep);
126
+ for (let i = 0; i < endOfPrefix; i++) {
127
+ if (compare[i] !== parts[i]) {
128
+ endOfPrefix = i;
129
+ }
130
+ }
131
+ if (endOfPrefix === 0)
132
+ return "";
133
+ }
134
+ const prefix = parts.slice(0, endOfPrefix).join(sep);
135
+ return prefix.endsWith(sep) ? prefix : prefix + sep;
136
+ };
137
+ }
138
+ });
139
+
105
140
  // src/index.ts
106
141
  var src_exports = {};
107
142
  __export(src_exports, {
@@ -120,7 +155,7 @@ __export(src_exports, {
120
155
  });
121
156
  module.exports = __toCommonJS(src_exports);
122
157
  var import_node_net = require("net");
123
- var import_node_path5 = require("path");
158
+ var import_node_path9 = require("path");
124
159
  var rsbuildReal = __toESM(require("@rsbuild/core"));
125
160
  var import_fs_extra = __toESM(require("fs-extra"));
126
161
  var import_pretty_hrtime = __toESM(require_pretty_hrtime());
@@ -130,7 +165,7 @@ var import_common3 = require("storybook/internal/common");
130
165
  var import_server_errors = require("storybook/internal/server-errors");
131
166
 
132
167
  // src/preview/iframe-rsbuild.config.ts
133
- var import_node_path3 = require("path");
168
+ var import_node_path7 = require("path");
134
169
  var import_core = require("@rsbuild/core");
135
170
  var import_plugin_type_check = require("@rsbuild/plugin-type-check");
136
171
  var import_preset = require("@storybook/addon-docs/preset");
@@ -141,19 +176,166 @@ var import_globals = require("storybook/internal/preview/globals");
141
176
  var import_ts_dedent2 = require("ts-dedent");
142
177
 
143
178
  // src/preview/virtual-module-mapping.ts
144
- var import_node_fs = __toESM(require("fs"));
145
- var import_node_path = __toESM(require("path"));
146
- var import_node_path2 = require("path");
179
+ var import_node_fs4 = __toESM(require("fs"));
180
+ var import_node_path5 = __toESM(require("path"));
181
+ var import_node_path6 = require("path");
147
182
  var import_core_webpack = require("@storybook/core-webpack");
148
- var import_find_cache_dir = __toESM(require("find-cache-dir"));
183
+
184
+ // ../../node_modules/.pnpm/find-cache-dir@5.0.0/node_modules/find-cache-dir/index.js
185
+ var import_node_process2 = __toESM(require("process"), 1);
186
+ var import_node_path4 = __toESM(require("path"), 1);
187
+ var import_node_fs3 = __toESM(require("fs"), 1);
188
+ var import_common_path_prefix = __toESM(require_common_path_prefix(), 1);
189
+
190
+ // ../../node_modules/.pnpm/pkg-dir@7.0.0/node_modules/pkg-dir/index.js
191
+ var import_node_path3 = __toESM(require("path"), 1);
192
+
193
+ // ../../node_modules/.pnpm/find-up@6.3.0/node_modules/find-up/index.js
194
+ var import_node_path2 = __toESM(require("path"), 1);
195
+ var import_node_url2 = require("url");
196
+
197
+ // ../../node_modules/.pnpm/locate-path@7.2.0/node_modules/locate-path/index.js
198
+ var import_node_process = __toESM(require("process"), 1);
199
+ var import_node_path = __toESM(require("path"), 1);
200
+ var import_node_fs = __toESM(require("fs"), 1);
201
+ var import_node_url = require("url");
202
+ var typeMappings = {
203
+ directory: "isDirectory",
204
+ file: "isFile"
205
+ };
206
+ function checkType(type) {
207
+ if (Object.hasOwnProperty.call(typeMappings, type)) {
208
+ return;
209
+ }
210
+ throw new Error(`Invalid type specified: ${type}`);
211
+ }
212
+ var matchType = (type, stat) => stat[typeMappings[type]]();
213
+ var toPath = (urlOrPath) => urlOrPath instanceof URL ? (0, import_node_url.fileURLToPath)(urlOrPath) : urlOrPath;
214
+ function locatePathSync(paths, {
215
+ cwd: cwd2 = import_node_process.default.cwd(),
216
+ type = "file",
217
+ allowSymlinks = true
218
+ } = {}) {
219
+ checkType(type);
220
+ cwd2 = toPath(cwd2);
221
+ const statFunction = allowSymlinks ? import_node_fs.default.statSync : import_node_fs.default.lstatSync;
222
+ for (const path_ of paths) {
223
+ try {
224
+ const stat = statFunction(import_node_path.default.resolve(cwd2, path_), {
225
+ throwIfNoEntry: false
226
+ });
227
+ if (!stat) {
228
+ continue;
229
+ }
230
+ if (matchType(type, stat)) {
231
+ return path_;
232
+ }
233
+ } catch {
234
+ }
235
+ }
236
+ }
237
+
238
+ // ../../node_modules/.pnpm/path-exists@5.0.0/node_modules/path-exists/index.js
239
+ var import_node_fs2 = __toESM(require("fs"), 1);
240
+
241
+ // ../../node_modules/.pnpm/find-up@6.3.0/node_modules/find-up/index.js
242
+ var toPath2 = (urlOrPath) => urlOrPath instanceof URL ? (0, import_node_url2.fileURLToPath)(urlOrPath) : urlOrPath;
243
+ var findUpStop = Symbol("findUpStop");
244
+ function findUpMultipleSync(name, options = {}) {
245
+ let directory = import_node_path2.default.resolve(toPath2(options.cwd) || "");
246
+ const { root } = import_node_path2.default.parse(directory);
247
+ const stopAt = options.stopAt || root;
248
+ const limit = options.limit || Number.POSITIVE_INFINITY;
249
+ const paths = [name].flat();
250
+ const runMatcher = (locateOptions) => {
251
+ if (typeof name !== "function") {
252
+ return locatePathSync(paths, locateOptions);
253
+ }
254
+ const foundPath = name(locateOptions.cwd);
255
+ if (typeof foundPath === "string") {
256
+ return locatePathSync([foundPath], locateOptions);
257
+ }
258
+ return foundPath;
259
+ };
260
+ const matches = [];
261
+ while (true) {
262
+ const foundPath = runMatcher({ ...options, cwd: directory });
263
+ if (foundPath === findUpStop) {
264
+ break;
265
+ }
266
+ if (foundPath) {
267
+ matches.push(import_node_path2.default.resolve(directory, foundPath));
268
+ }
269
+ if (directory === stopAt || matches.length >= limit) {
270
+ break;
271
+ }
272
+ directory = import_node_path2.default.dirname(directory);
273
+ }
274
+ return matches;
275
+ }
276
+ function findUpSync(name, options = {}) {
277
+ const matches = findUpMultipleSync(name, { ...options, limit: 1 });
278
+ return matches[0];
279
+ }
280
+
281
+ // ../../node_modules/.pnpm/pkg-dir@7.0.0/node_modules/pkg-dir/index.js
282
+ function packageDirectorySync({ cwd: cwd2 } = {}) {
283
+ const filePath = findUpSync("package.json", { cwd: cwd2 });
284
+ return filePath && import_node_path3.default.dirname(filePath);
285
+ }
286
+
287
+ // ../../node_modules/.pnpm/find-cache-dir@5.0.0/node_modules/find-cache-dir/index.js
288
+ var { env, cwd } = import_node_process2.default;
289
+ var isWritable = (path6) => {
290
+ try {
291
+ import_node_fs3.default.accessSync(path6, import_node_fs3.default.constants.W_OK);
292
+ return true;
293
+ } catch {
294
+ return false;
295
+ }
296
+ };
297
+ function useDirectory(directory, options) {
298
+ if (options.create) {
299
+ import_node_fs3.default.mkdirSync(directory, { recursive: true });
300
+ }
301
+ return directory;
302
+ }
303
+ function getNodeModuleDirectory(directory) {
304
+ const nodeModules = import_node_path4.default.join(directory, "node_modules");
305
+ if (!isWritable(nodeModules) && (import_node_fs3.default.existsSync(nodeModules) || !isWritable(import_node_path4.default.join(directory)))) {
306
+ return;
307
+ }
308
+ return nodeModules;
309
+ }
310
+ function findCacheDirectory(options = {}) {
311
+ if (env.CACHE_DIR && !["true", "false", "1", "0"].includes(env.CACHE_DIR)) {
312
+ return useDirectory(import_node_path4.default.join(env.CACHE_DIR, options.name), options);
313
+ }
314
+ let { cwd: directory = cwd(), files } = options;
315
+ if (files) {
316
+ if (!Array.isArray(files)) {
317
+ throw new TypeError(`Expected \`files\` option to be an array, got \`${typeof files}\`.`);
318
+ }
319
+ directory = (0, import_common_path_prefix.default)(files.map((file) => import_node_path4.default.resolve(directory, file)));
320
+ }
321
+ directory = packageDirectorySync({ cwd: directory });
322
+ if (!directory) {
323
+ return;
324
+ }
325
+ const nodeModules = getNodeModuleDirectory(directory);
326
+ if (!nodeModules) {
327
+ return;
328
+ }
329
+ return useDirectory(import_node_path4.default.join(directory, "node_modules", ".cache", options.name), options);
330
+ }
149
331
 
150
332
  // ../../node_modules/.pnpm/slash@5.1.0/node_modules/slash/index.js
151
- function slash(path2) {
152
- const isExtendedLengthPath = path2.startsWith("\\\\?\\");
333
+ function slash(path6) {
334
+ const isExtendedLengthPath = path6.startsWith("\\\\?\\");
153
335
  if (isExtendedLengthPath) {
154
- return path2;
336
+ return path6;
155
337
  }
156
- return path2.replace(/\\/g, "/");
338
+ return path6.replace(/\\/g, "/");
157
339
  }
158
340
 
159
341
  // src/preview/virtual-module-mapping.ts
@@ -161,17 +343,17 @@ var import_common = require("storybook/internal/common");
161
343
  var import_ts_dedent = require("ts-dedent");
162
344
  var getVirtualModules = async (options) => {
163
345
  const virtualModules = {};
164
- const cwd = process.cwd();
346
+ const cwd2 = process.cwd();
165
347
  const workingDir = options.cache ? (
166
348
  // TODO: This is a hard code cache dir, as Rspack doesn't support virtual modules now.
167
349
  // Remove this when Rspack supports virtual modules.
168
- (0, import_find_cache_dir.default)({
350
+ findCacheDirectory({
169
351
  name: "storybook-rsbuild-builder",
170
352
  create: true
171
353
  })
172
354
  ) : process.cwd();
173
- if (!import_node_fs.default.existsSync(workingDir)) {
174
- import_node_fs.default.mkdirSync(workingDir, { recursive: true });
355
+ if (!import_node_fs4.default.existsSync(workingDir)) {
356
+ import_node_fs4.default.mkdirSync(workingDir, { recursive: true });
175
357
  }
176
358
  const isProd = options.configType === "PRODUCTION";
177
359
  const nonNormalizedStories = await options.presets.apply("stories", []);
@@ -180,7 +362,7 @@ var getVirtualModules = async (options) => {
180
362
  configDir: options.configDir,
181
363
  workingDir
182
364
  });
183
- const realPathRelativeToCwd = import_node_path.default.relative(workingDir, cwd).split(import_node_path.default.sep).join(import_node_path.default.posix.sep);
365
+ const realPathRelativeToCwd = import_node_path5.default.relative(workingDir, cwd2).split(import_node_path5.default.sep).join(import_node_path5.default.posix.sep);
184
366
  const previewAnnotations = [
185
367
  ...(await options.presets.apply(
186
368
  "previewAnnotations",
@@ -195,13 +377,13 @@ var getVirtualModules = async (options) => {
195
377
  (0, import_common.loadPreviewOrConfigFile)(options)
196
378
  ].filter(Boolean);
197
379
  const storiesFilename = "storybook-stories.js";
198
- const storiesPath = (0, import_node_path2.resolve)((0, import_node_path2.join)(workingDir, storiesFilename));
380
+ const storiesPath = (0, import_node_path6.resolve)((0, import_node_path6.join)(workingDir, storiesFilename));
199
381
  const builderOptions = await (0, import_common.getBuilderOptions)(options);
200
382
  const needPipelinedImport = !!builderOptions.lazyCompilation && !isProd;
201
383
  virtualModules[storiesPath] = toImportFn(stories, realPathRelativeToCwd, {
202
384
  needPipelinedImport
203
385
  });
204
- const configEntryPath = (0, import_node_path2.resolve)((0, import_node_path2.join)(workingDir, "storybook-config-entry.js"));
386
+ const configEntryPath = (0, import_node_path6.resolve)((0, import_node_path6.join)(workingDir, "storybook-config-entry.js"));
205
387
  virtualModules[configEntryPath] = (await (0, import_common.readTemplate)(
206
388
  require.resolve("storybook-builder-rsbuild/templates/virtualModuleModernEntry.js")
207
389
  )).replaceAll(`'{{storiesFilename}}'`, `'./${storiesFilename}'`).replaceAll(
@@ -213,7 +395,7 @@ var getVirtualModules = async (options) => {
213
395
  ).replace(/\\/g, "\\\\");
214
396
  entries.push(configEntryPath);
215
397
  for (const [key, value] of Object.entries(virtualModules)) {
216
- import_node_fs.default.writeFileSync(key, value);
398
+ import_node_fs4.default.writeFileSync(key, value);
217
399
  }
218
400
  return {
219
401
  virtualModules,
@@ -288,7 +470,7 @@ function importPipeline() {
288
470
  }
289
471
 
290
472
  // src/preview/iframe-rsbuild.config.ts
291
- var getAbsolutePath = (input) => (0, import_node_path3.dirname)(require.resolve((0, import_node_path3.join)(input, "package.json")));
473
+ var getAbsolutePath = (input) => (0, import_node_path7.dirname)(require.resolve((0, import_node_path7.join)(input, "package.json")));
292
474
  var maybeGetAbsolutePath = (input) => {
293
475
  try {
294
476
  return getAbsolutePath(input);
@@ -323,7 +505,7 @@ var iframe_rsbuild_config_default = async (options, extraWebpackConfig) => {
323
505
  const { rsbuildConfigPath, addonDocs } = await (0, import_common2.getBuilderOptions)(options);
324
506
  const appliedDocsWebpack = await (0, import_preset.webpack)({}, { ...options, ...addonDocs });
325
507
  const {
326
- outputDir = (0, import_node_path3.join)(".", "public"),
508
+ outputDir = (0, import_node_path7.join)(".", "public"),
327
509
  quiet,
328
510
  packageJson,
329
511
  configType,
@@ -441,7 +623,7 @@ var iframe_rsbuild_config_default = async (options, extraWebpackConfig) => {
441
623
  css: !options.build?.test?.disableSourcemaps
442
624
  },
443
625
  distPath: {
444
- root: (0, import_node_path3.resolve)(process.cwd(), outputDir)
626
+ root: (0, import_node_path7.resolve)(process.cwd(), outputDir)
445
627
  },
446
628
  filename: {
447
629
  js: isProd ? "[name].[contenthash:8].iframe.bundle.js" : "[name].iframe.bundle.js",
@@ -592,7 +774,7 @@ var iframe_rsbuild_config_default = async (options, extraWebpackConfig) => {
592
774
 
593
775
  // src/react-shims.ts
594
776
  var import_promises = require("fs/promises");
595
- var import_node_path4 = require("path");
777
+ var import_node_path8 = require("path");
596
778
  var getIsReactVersion18or19 = async (options) => {
597
779
  const { legacyRootApi } = await options.presets.apply(
598
780
  "frameworkOptions"
@@ -604,12 +786,12 @@ var getIsReactVersion18or19 = async (options) => {
604
786
  "resolvedReact",
605
787
  {}
606
788
  );
607
- const reactDom = resolvedReact.reactDom || (0, import_node_path4.dirname)(require.resolve("react-dom/package.json"));
608
- if (!(0, import_node_path4.isAbsolute)(reactDom)) {
789
+ const reactDom = resolvedReact.reactDom || (0, import_node_path8.dirname)(require.resolve("react-dom/package.json"));
790
+ if (!(0, import_node_path8.isAbsolute)(reactDom)) {
609
791
  return false;
610
792
  }
611
793
  const { version } = JSON.parse(
612
- await (0, import_promises.readFile)((0, import_node_path4.join)(reactDom, "package.json"), "utf-8")
794
+ await (0, import_promises.readFile)((0, import_node_path8.join)(reactDom, "package.json"), "utf-8")
613
795
  );
614
796
  return version.startsWith("18") || version.startsWith("19") || version.startsWith("0.0.0");
615
797
  };
@@ -735,7 +917,7 @@ var start = async ({
735
917
  error: new Error("Missing Rsbuild build instance at runtime!")
736
918
  });
737
919
  }
738
- const previewResolvedDir = (0, import_node_path5.join)(import_core_path.corePath, "dist/preview");
920
+ const previewResolvedDir = (0, import_node_path9.join)(import_core_path.corePath, "dist/preview");
739
921
  const previewDirOrigin = previewResolvedDir;
740
922
  router.use(
741
923
  "/sb-preview",
@@ -758,16 +940,16 @@ var build = async ({ options }) => {
758
940
  cwd: process.cwd(),
759
941
  rsbuildConfig: config
760
942
  });
761
- const previewResolvedDir = (0, import_node_path5.join)(import_core_path.corePath, "dist/preview");
943
+ const previewResolvedDir = (0, import_node_path9.join)(import_core_path.corePath, "dist/preview");
762
944
  const previewDirOrigin = previewResolvedDir;
763
- const previewDirTarget = (0, import_node_path5.join)(options.outputDir || "", "sb-preview");
945
+ const previewDirTarget = (0, import_node_path9.join)(options.outputDir || "", "sb-preview");
764
946
  let stats;
765
947
  rsbuildBuild.onAfterBuild((params) => {
766
948
  stats = params.stats;
767
949
  });
768
950
  const previewFiles = import_fs_extra.default.copy(previewDirOrigin, previewDirTarget, {
769
951
  filter: (src) => {
770
- const { ext } = (0, import_node_path5.parse)(src);
952
+ const { ext } = (0, import_node_path9.parse)(src);
771
953
  if (ext) {
772
954
  return ext === ".js";
773
955
  }
@@ -781,7 +963,7 @@ var build = async ({ options }) => {
781
963
  await close();
782
964
  return stats;
783
965
  };
784
- var corePresets = [(0, import_node_path5.join)(__dirname, "./preview-preset.js")];
966
+ var corePresets = [(0, import_node_path9.join)(__dirname, "./preview-preset.js")];
785
967
  var previewMainTemplate = () => require.resolve("storybook-builder-rsbuild/templates/preview.ejs");
786
968
  function getRandomPort(host) {
787
969
  return new Promise((resolve3, reject) => {
package/dist/index.mjs CHANGED
@@ -1,9 +1,9 @@
1
- import { __commonJS, __toESM, __require } from './chunk-TTFRSOOU.mjs';
1
+ import { __commonJS, __require, __toESM } from './chunk-TTFRSOOU.mjs';
2
2
  import { createServer } from 'net';
3
- import path, { join, resolve, parse, dirname, isAbsolute } from 'path';
3
+ import path4, { join, resolve, parse, dirname, isAbsolute } from 'path';
4
4
  import * as rsbuildReal from '@rsbuild/core';
5
5
  import { loadConfig, mergeRsbuildConfig } from '@rsbuild/core';
6
- import fs2 from 'fs-extra';
6
+ import fs4 from 'fs-extra';
7
7
  import sirv from 'sirv';
8
8
  import { corePath } from 'storybook/core-path';
9
9
  import { normalizeStories, loadPreviewOrConfigFile, getBuilderOptions, readTemplate, resolveAddonName, getPresets, stringifyProcessEnvs, isPreservingSymlinks } from 'storybook/internal/common';
@@ -14,9 +14,10 @@ import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin';
14
14
  import { pluginHtmlMinifierTerser } from 'rsbuild-plugin-html-minifier-terser';
15
15
  import { globalsNameReferenceMap } from 'storybook/internal/preview/globals';
16
16
  import { dedent } from 'ts-dedent';
17
- import fs from 'fs';
17
+ import fs2 from 'fs';
18
18
  import { webpackIncludeRegexp } from '@storybook/core-webpack';
19
- import findCacheDirectory from 'find-cache-dir';
19
+ import process2 from 'process';
20
+ import { fileURLToPath } from 'url';
20
21
  import { readFile } from 'fs/promises';
21
22
 
22
23
  // ../../node_modules/.pnpm/pretty-hrtime@1.0.3/node_modules/pretty-hrtime/index.js
@@ -90,20 +91,183 @@ var require_pretty_hrtime = __commonJS({
90
91
  }
91
92
  });
92
93
 
94
+ // ../../node_modules/.pnpm/common-path-prefix@3.0.0/node_modules/common-path-prefix/index.js
95
+ var require_common_path_prefix = __commonJS({
96
+ "../../node_modules/.pnpm/common-path-prefix@3.0.0/node_modules/common-path-prefix/index.js"(exports, module) {
97
+ var { sep: DEFAULT_SEPARATOR } = __require("path");
98
+ var determineSeparator = (paths) => {
99
+ for (const path6 of paths) {
100
+ const match = /(\/|\\)/.exec(path6);
101
+ if (match !== null)
102
+ return match[0];
103
+ }
104
+ return DEFAULT_SEPARATOR;
105
+ };
106
+ module.exports = function commonPathPrefix2(paths, sep = determineSeparator(paths)) {
107
+ const [first = "", ...remaining] = paths;
108
+ if (first === "" || remaining.length === 0)
109
+ return "";
110
+ const parts = first.split(sep);
111
+ let endOfPrefix = parts.length;
112
+ for (const path6 of remaining) {
113
+ const compare = path6.split(sep);
114
+ for (let i = 0; i < endOfPrefix; i++) {
115
+ if (compare[i] !== parts[i]) {
116
+ endOfPrefix = i;
117
+ }
118
+ }
119
+ if (endOfPrefix === 0)
120
+ return "";
121
+ }
122
+ const prefix = parts.slice(0, endOfPrefix).join(sep);
123
+ return prefix.endsWith(sep) ? prefix : prefix + sep;
124
+ };
125
+ }
126
+ });
127
+
93
128
  // src/index.ts
94
129
  var import_pretty_hrtime = __toESM(require_pretty_hrtime());
95
130
 
131
+ // ../../node_modules/.pnpm/find-cache-dir@5.0.0/node_modules/find-cache-dir/index.js
132
+ var import_common_path_prefix = __toESM(require_common_path_prefix(), 1);
133
+ var typeMappings = {
134
+ directory: "isDirectory",
135
+ file: "isFile"
136
+ };
137
+ function checkType(type) {
138
+ if (Object.hasOwnProperty.call(typeMappings, type)) {
139
+ return;
140
+ }
141
+ throw new Error(`Invalid type specified: ${type}`);
142
+ }
143
+ var matchType = (type, stat) => stat[typeMappings[type]]();
144
+ var toPath = (urlOrPath) => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;
145
+ function locatePathSync(paths, {
146
+ cwd: cwd2 = process2.cwd(),
147
+ type = "file",
148
+ allowSymlinks = true
149
+ } = {}) {
150
+ checkType(type);
151
+ cwd2 = toPath(cwd2);
152
+ const statFunction = allowSymlinks ? fs2.statSync : fs2.lstatSync;
153
+ for (const path_ of paths) {
154
+ try {
155
+ const stat = statFunction(path4.resolve(cwd2, path_), {
156
+ throwIfNoEntry: false
157
+ });
158
+ if (!stat) {
159
+ continue;
160
+ }
161
+ if (matchType(type, stat)) {
162
+ return path_;
163
+ }
164
+ } catch {
165
+ }
166
+ }
167
+ }
168
+
169
+ // ../../node_modules/.pnpm/find-up@6.3.0/node_modules/find-up/index.js
170
+ var toPath2 = (urlOrPath) => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;
171
+ var findUpStop = Symbol("findUpStop");
172
+ function findUpMultipleSync(name, options = {}) {
173
+ let directory = path4.resolve(toPath2(options.cwd) || "");
174
+ const { root } = path4.parse(directory);
175
+ const stopAt = options.stopAt || root;
176
+ const limit = options.limit || Number.POSITIVE_INFINITY;
177
+ const paths = [name].flat();
178
+ const runMatcher = (locateOptions) => {
179
+ if (typeof name !== "function") {
180
+ return locatePathSync(paths, locateOptions);
181
+ }
182
+ const foundPath = name(locateOptions.cwd);
183
+ if (typeof foundPath === "string") {
184
+ return locatePathSync([foundPath], locateOptions);
185
+ }
186
+ return foundPath;
187
+ };
188
+ const matches = [];
189
+ while (true) {
190
+ const foundPath = runMatcher({ ...options, cwd: directory });
191
+ if (foundPath === findUpStop) {
192
+ break;
193
+ }
194
+ if (foundPath) {
195
+ matches.push(path4.resolve(directory, foundPath));
196
+ }
197
+ if (directory === stopAt || matches.length >= limit) {
198
+ break;
199
+ }
200
+ directory = path4.dirname(directory);
201
+ }
202
+ return matches;
203
+ }
204
+ function findUpSync(name, options = {}) {
205
+ const matches = findUpMultipleSync(name, { ...options, limit: 1 });
206
+ return matches[0];
207
+ }
208
+
209
+ // ../../node_modules/.pnpm/pkg-dir@7.0.0/node_modules/pkg-dir/index.js
210
+ function packageDirectorySync({ cwd: cwd2 } = {}) {
211
+ const filePath = findUpSync("package.json", { cwd: cwd2 });
212
+ return filePath && path4.dirname(filePath);
213
+ }
214
+
215
+ // ../../node_modules/.pnpm/find-cache-dir@5.0.0/node_modules/find-cache-dir/index.js
216
+ var { env, cwd } = process2;
217
+ var isWritable = (path6) => {
218
+ try {
219
+ fs2.accessSync(path6, fs2.constants.W_OK);
220
+ return true;
221
+ } catch {
222
+ return false;
223
+ }
224
+ };
225
+ function useDirectory(directory, options) {
226
+ if (options.create) {
227
+ fs2.mkdirSync(directory, { recursive: true });
228
+ }
229
+ return directory;
230
+ }
231
+ function getNodeModuleDirectory(directory) {
232
+ const nodeModules = path4.join(directory, "node_modules");
233
+ if (!isWritable(nodeModules) && (fs2.existsSync(nodeModules) || !isWritable(path4.join(directory)))) {
234
+ return;
235
+ }
236
+ return nodeModules;
237
+ }
238
+ function findCacheDirectory(options = {}) {
239
+ if (env.CACHE_DIR && !["true", "false", "1", "0"].includes(env.CACHE_DIR)) {
240
+ return useDirectory(path4.join(env.CACHE_DIR, options.name), options);
241
+ }
242
+ let { cwd: directory = cwd(), files } = options;
243
+ if (files) {
244
+ if (!Array.isArray(files)) {
245
+ throw new TypeError(`Expected \`files\` option to be an array, got \`${typeof files}\`.`);
246
+ }
247
+ directory = (0, import_common_path_prefix.default)(files.map((file) => path4.resolve(directory, file)));
248
+ }
249
+ directory = packageDirectorySync({ cwd: directory });
250
+ if (!directory) {
251
+ return;
252
+ }
253
+ const nodeModules = getNodeModuleDirectory(directory);
254
+ if (!nodeModules) {
255
+ return;
256
+ }
257
+ return useDirectory(path4.join(directory, "node_modules", ".cache", options.name), options);
258
+ }
259
+
96
260
  // ../../node_modules/.pnpm/slash@5.1.0/node_modules/slash/index.js
97
- function slash(path2) {
98
- const isExtendedLengthPath = path2.startsWith("\\\\?\\");
261
+ function slash(path6) {
262
+ const isExtendedLengthPath = path6.startsWith("\\\\?\\");
99
263
  if (isExtendedLengthPath) {
100
- return path2;
264
+ return path6;
101
265
  }
102
- return path2.replace(/\\/g, "/");
266
+ return path6.replace(/\\/g, "/");
103
267
  }
104
268
  var getVirtualModules = async (options) => {
105
269
  const virtualModules = {};
106
- const cwd = process.cwd();
270
+ const cwd2 = process.cwd();
107
271
  const workingDir = options.cache ? (
108
272
  // TODO: This is a hard code cache dir, as Rspack doesn't support virtual modules now.
109
273
  // Remove this when Rspack supports virtual modules.
@@ -112,8 +276,8 @@ var getVirtualModules = async (options) => {
112
276
  create: true
113
277
  })
114
278
  ) : process.cwd();
115
- if (!fs.existsSync(workingDir)) {
116
- fs.mkdirSync(workingDir, { recursive: true });
279
+ if (!fs2.existsSync(workingDir)) {
280
+ fs2.mkdirSync(workingDir, { recursive: true });
117
281
  }
118
282
  const isProd = options.configType === "PRODUCTION";
119
283
  const nonNormalizedStories = await options.presets.apply("stories", []);
@@ -122,7 +286,7 @@ var getVirtualModules = async (options) => {
122
286
  configDir: options.configDir,
123
287
  workingDir
124
288
  });
125
- const realPathRelativeToCwd = path.relative(workingDir, cwd).split(path.sep).join(path.posix.sep);
289
+ const realPathRelativeToCwd = path4.relative(workingDir, cwd2).split(path4.sep).join(path4.posix.sep);
126
290
  const previewAnnotations = [
127
291
  ...(await options.presets.apply(
128
292
  "previewAnnotations",
@@ -157,7 +321,7 @@ var getVirtualModules = async (options) => {
157
321
  ).replace(/\\/g, "\\\\");
158
322
  entries.push(configEntryPath);
159
323
  for (const [key, value] of Object.entries(virtualModules)) {
160
- fs.writeFileSync(key, value);
324
+ fs2.writeFileSync(key, value);
161
325
  }
162
326
  return {
163
327
  virtualModules,
@@ -707,7 +871,7 @@ var build = async ({ options }) => {
707
871
  rsbuildBuild.onAfterBuild((params) => {
708
872
  stats = params.stats;
709
873
  });
710
- const previewFiles = fs2.copy(previewDirOrigin, previewDirTarget, {
874
+ const previewFiles = fs4.copy(previewDirOrigin, previewDirTarget, {
711
875
  filter: (src) => {
712
876
  const { ext } = parse(src);
713
877
  if (ext) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "storybook-builder-rsbuild",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Rsbuild builder for Storybook",
5
5
  "keywords": [
6
6
  "storybook",
@@ -65,7 +65,6 @@
65
65
  "cjs-module-lexer": "^1.4.3",
66
66
  "constants-browserify": "^1.0.0",
67
67
  "es-module-lexer": "^1.6.0",
68
- "find-cache-dir": "^5.0.0",
69
68
  "fs-extra": "^11.3.0",
70
69
  "magic-string": "^0.30.17",
71
70
  "path-browserify": "^1.0.1",
@@ -83,6 +82,7 @@
83
82
  "@types/fs-extra": "^11.0.4",
84
83
  "@types/node": "^18.0.0",
85
84
  "@types/pretty-hrtime": "^1.0.3",
85
+ "find-cache-dir": "^5.0.0",
86
86
  "pretty-hrtime": "^1.0.3",
87
87
  "slash": "^5.1.0",
88
88
  "storybook": "8.6.14",