storybook-builder-rsbuild 2.0.3 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +213 -31
- package/dist/index.mjs +179 -15
- package/package.json +3 -3
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
|
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());
|
@@ -129,7 +164,7 @@ var import_common3 = require("storybook/internal/common");
|
|
129
164
|
var import_server_errors = require("storybook/internal/server-errors");
|
130
165
|
|
131
166
|
// src/preview/iframe-rsbuild.config.ts
|
132
|
-
var
|
167
|
+
var import_node_path7 = require("path");
|
133
168
|
var import_core = require("@rsbuild/core");
|
134
169
|
var import_plugin_type_check = require("@rsbuild/plugin-type-check");
|
135
170
|
var import_preset = require("@storybook/addon-docs/preset");
|
@@ -140,19 +175,166 @@ var import_globals = require("storybook/internal/preview/globals");
|
|
140
175
|
var import_ts_dedent2 = require("ts-dedent");
|
141
176
|
|
142
177
|
// src/preview/virtual-module-mapping.ts
|
143
|
-
var
|
144
|
-
var
|
145
|
-
var
|
178
|
+
var import_node_fs4 = __toESM(require("fs"));
|
179
|
+
var import_node_path5 = __toESM(require("path"));
|
180
|
+
var import_node_path6 = require("path");
|
146
181
|
var import_core_webpack = require("@storybook/core-webpack");
|
147
|
-
|
182
|
+
|
183
|
+
// ../../node_modules/.pnpm/find-cache-dir@5.0.0/node_modules/find-cache-dir/index.js
|
184
|
+
var import_node_process2 = __toESM(require("process"), 1);
|
185
|
+
var import_node_path4 = __toESM(require("path"), 1);
|
186
|
+
var import_node_fs3 = __toESM(require("fs"), 1);
|
187
|
+
var import_common_path_prefix = __toESM(require_common_path_prefix(), 1);
|
188
|
+
|
189
|
+
// ../../node_modules/.pnpm/pkg-dir@7.0.0/node_modules/pkg-dir/index.js
|
190
|
+
var import_node_path3 = __toESM(require("path"), 1);
|
191
|
+
|
192
|
+
// ../../node_modules/.pnpm/find-up@6.3.0/node_modules/find-up/index.js
|
193
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
194
|
+
var import_node_url2 = require("url");
|
195
|
+
|
196
|
+
// ../../node_modules/.pnpm/locate-path@7.2.0/node_modules/locate-path/index.js
|
197
|
+
var import_node_process = __toESM(require("process"), 1);
|
198
|
+
var import_node_path = __toESM(require("path"), 1);
|
199
|
+
var import_node_fs = __toESM(require("fs"), 1);
|
200
|
+
var import_node_url = require("url");
|
201
|
+
var typeMappings = {
|
202
|
+
directory: "isDirectory",
|
203
|
+
file: "isFile"
|
204
|
+
};
|
205
|
+
function checkType(type) {
|
206
|
+
if (Object.hasOwnProperty.call(typeMappings, type)) {
|
207
|
+
return;
|
208
|
+
}
|
209
|
+
throw new Error(`Invalid type specified: ${type}`);
|
210
|
+
}
|
211
|
+
var matchType = (type, stat) => stat[typeMappings[type]]();
|
212
|
+
var toPath = (urlOrPath) => urlOrPath instanceof URL ? (0, import_node_url.fileURLToPath)(urlOrPath) : urlOrPath;
|
213
|
+
function locatePathSync(paths, {
|
214
|
+
cwd: cwd2 = import_node_process.default.cwd(),
|
215
|
+
type = "file",
|
216
|
+
allowSymlinks = true
|
217
|
+
} = {}) {
|
218
|
+
checkType(type);
|
219
|
+
cwd2 = toPath(cwd2);
|
220
|
+
const statFunction = allowSymlinks ? import_node_fs.default.statSync : import_node_fs.default.lstatSync;
|
221
|
+
for (const path_ of paths) {
|
222
|
+
try {
|
223
|
+
const stat = statFunction(import_node_path.default.resolve(cwd2, path_), {
|
224
|
+
throwIfNoEntry: false
|
225
|
+
});
|
226
|
+
if (!stat) {
|
227
|
+
continue;
|
228
|
+
}
|
229
|
+
if (matchType(type, stat)) {
|
230
|
+
return path_;
|
231
|
+
}
|
232
|
+
} catch {
|
233
|
+
}
|
234
|
+
}
|
235
|
+
}
|
236
|
+
|
237
|
+
// ../../node_modules/.pnpm/path-exists@5.0.0/node_modules/path-exists/index.js
|
238
|
+
var import_node_fs2 = __toESM(require("fs"), 1);
|
239
|
+
|
240
|
+
// ../../node_modules/.pnpm/find-up@6.3.0/node_modules/find-up/index.js
|
241
|
+
var toPath2 = (urlOrPath) => urlOrPath instanceof URL ? (0, import_node_url2.fileURLToPath)(urlOrPath) : urlOrPath;
|
242
|
+
var findUpStop = Symbol("findUpStop");
|
243
|
+
function findUpMultipleSync(name, options = {}) {
|
244
|
+
let directory = import_node_path2.default.resolve(toPath2(options.cwd) || "");
|
245
|
+
const { root } = import_node_path2.default.parse(directory);
|
246
|
+
const stopAt = options.stopAt || root;
|
247
|
+
const limit = options.limit || Number.POSITIVE_INFINITY;
|
248
|
+
const paths = [name].flat();
|
249
|
+
const runMatcher = (locateOptions) => {
|
250
|
+
if (typeof name !== "function") {
|
251
|
+
return locatePathSync(paths, locateOptions);
|
252
|
+
}
|
253
|
+
const foundPath = name(locateOptions.cwd);
|
254
|
+
if (typeof foundPath === "string") {
|
255
|
+
return locatePathSync([foundPath], locateOptions);
|
256
|
+
}
|
257
|
+
return foundPath;
|
258
|
+
};
|
259
|
+
const matches = [];
|
260
|
+
while (true) {
|
261
|
+
const foundPath = runMatcher({ ...options, cwd: directory });
|
262
|
+
if (foundPath === findUpStop) {
|
263
|
+
break;
|
264
|
+
}
|
265
|
+
if (foundPath) {
|
266
|
+
matches.push(import_node_path2.default.resolve(directory, foundPath));
|
267
|
+
}
|
268
|
+
if (directory === stopAt || matches.length >= limit) {
|
269
|
+
break;
|
270
|
+
}
|
271
|
+
directory = import_node_path2.default.dirname(directory);
|
272
|
+
}
|
273
|
+
return matches;
|
274
|
+
}
|
275
|
+
function findUpSync(name, options = {}) {
|
276
|
+
const matches = findUpMultipleSync(name, { ...options, limit: 1 });
|
277
|
+
return matches[0];
|
278
|
+
}
|
279
|
+
|
280
|
+
// ../../node_modules/.pnpm/pkg-dir@7.0.0/node_modules/pkg-dir/index.js
|
281
|
+
function packageDirectorySync({ cwd: cwd2 } = {}) {
|
282
|
+
const filePath = findUpSync("package.json", { cwd: cwd2 });
|
283
|
+
return filePath && import_node_path3.default.dirname(filePath);
|
284
|
+
}
|
285
|
+
|
286
|
+
// ../../node_modules/.pnpm/find-cache-dir@5.0.0/node_modules/find-cache-dir/index.js
|
287
|
+
var { env, cwd } = import_node_process2.default;
|
288
|
+
var isWritable = (path6) => {
|
289
|
+
try {
|
290
|
+
import_node_fs3.default.accessSync(path6, import_node_fs3.default.constants.W_OK);
|
291
|
+
return true;
|
292
|
+
} catch {
|
293
|
+
return false;
|
294
|
+
}
|
295
|
+
};
|
296
|
+
function useDirectory(directory, options) {
|
297
|
+
if (options.create) {
|
298
|
+
import_node_fs3.default.mkdirSync(directory, { recursive: true });
|
299
|
+
}
|
300
|
+
return directory;
|
301
|
+
}
|
302
|
+
function getNodeModuleDirectory(directory) {
|
303
|
+
const nodeModules = import_node_path4.default.join(directory, "node_modules");
|
304
|
+
if (!isWritable(nodeModules) && (import_node_fs3.default.existsSync(nodeModules) || !isWritable(import_node_path4.default.join(directory)))) {
|
305
|
+
return;
|
306
|
+
}
|
307
|
+
return nodeModules;
|
308
|
+
}
|
309
|
+
function findCacheDirectory(options = {}) {
|
310
|
+
if (env.CACHE_DIR && !["true", "false", "1", "0"].includes(env.CACHE_DIR)) {
|
311
|
+
return useDirectory(import_node_path4.default.join(env.CACHE_DIR, options.name), options);
|
312
|
+
}
|
313
|
+
let { cwd: directory = cwd(), files } = options;
|
314
|
+
if (files) {
|
315
|
+
if (!Array.isArray(files)) {
|
316
|
+
throw new TypeError(`Expected \`files\` option to be an array, got \`${typeof files}\`.`);
|
317
|
+
}
|
318
|
+
directory = (0, import_common_path_prefix.default)(files.map((file) => import_node_path4.default.resolve(directory, file)));
|
319
|
+
}
|
320
|
+
directory = packageDirectorySync({ cwd: directory });
|
321
|
+
if (!directory) {
|
322
|
+
return;
|
323
|
+
}
|
324
|
+
const nodeModules = getNodeModuleDirectory(directory);
|
325
|
+
if (!nodeModules) {
|
326
|
+
return;
|
327
|
+
}
|
328
|
+
return useDirectory(import_node_path4.default.join(directory, "node_modules", ".cache", options.name), options);
|
329
|
+
}
|
148
330
|
|
149
331
|
// ../../node_modules/.pnpm/slash@5.1.0/node_modules/slash/index.js
|
150
|
-
function slash(
|
151
|
-
const isExtendedLengthPath =
|
332
|
+
function slash(path6) {
|
333
|
+
const isExtendedLengthPath = path6.startsWith("\\\\?\\");
|
152
334
|
if (isExtendedLengthPath) {
|
153
|
-
return
|
335
|
+
return path6;
|
154
336
|
}
|
155
|
-
return
|
337
|
+
return path6.replace(/\\/g, "/");
|
156
338
|
}
|
157
339
|
|
158
340
|
// src/preview/virtual-module-mapping.ts
|
@@ -160,17 +342,17 @@ var import_common = require("storybook/internal/common");
|
|
160
342
|
var import_ts_dedent = require("ts-dedent");
|
161
343
|
var getVirtualModules = async (options) => {
|
162
344
|
const virtualModules = {};
|
163
|
-
const
|
345
|
+
const cwd2 = process.cwd();
|
164
346
|
const workingDir = options.cache ? (
|
165
347
|
// TODO: This is a hard code cache dir, as Rspack doesn't support virtual modules now.
|
166
348
|
// Remove this when Rspack supports virtual modules.
|
167
|
-
(
|
349
|
+
findCacheDirectory({
|
168
350
|
name: "storybook-rsbuild-builder",
|
169
351
|
create: true
|
170
352
|
})
|
171
353
|
) : process.cwd();
|
172
|
-
if (!
|
173
|
-
|
354
|
+
if (!import_node_fs4.default.existsSync(workingDir)) {
|
355
|
+
import_node_fs4.default.mkdirSync(workingDir, { recursive: true });
|
174
356
|
}
|
175
357
|
const isProd = options.configType === "PRODUCTION";
|
176
358
|
const nonNormalizedStories = await options.presets.apply("stories", []);
|
@@ -179,7 +361,7 @@ var getVirtualModules = async (options) => {
|
|
179
361
|
configDir: options.configDir,
|
180
362
|
workingDir
|
181
363
|
});
|
182
|
-
const realPathRelativeToCwd =
|
364
|
+
const realPathRelativeToCwd = import_node_path5.default.relative(workingDir, cwd2).split(import_node_path5.default.sep).join(import_node_path5.default.posix.sep);
|
183
365
|
const previewAnnotations = [
|
184
366
|
...(await options.presets.apply(
|
185
367
|
"previewAnnotations",
|
@@ -194,13 +376,13 @@ var getVirtualModules = async (options) => {
|
|
194
376
|
(0, import_common.loadPreviewOrConfigFile)(options)
|
195
377
|
].filter(Boolean);
|
196
378
|
const storiesFilename = "storybook-stories.js";
|
197
|
-
const storiesPath = (0,
|
379
|
+
const storiesPath = (0, import_node_path6.resolve)((0, import_node_path6.join)(workingDir, storiesFilename));
|
198
380
|
const builderOptions = await (0, import_common.getBuilderOptions)(options);
|
199
381
|
const needPipelinedImport = !!builderOptions.lazyCompilation && !isProd;
|
200
382
|
virtualModules[storiesPath] = toImportFn(stories, realPathRelativeToCwd, {
|
201
383
|
needPipelinedImport
|
202
384
|
});
|
203
|
-
const configEntryPath = (0,
|
385
|
+
const configEntryPath = (0, import_node_path6.resolve)((0, import_node_path6.join)(workingDir, "storybook-config-entry.js"));
|
204
386
|
virtualModules[configEntryPath] = (await (0, import_common.readTemplate)(
|
205
387
|
require.resolve("storybook-builder-rsbuild/templates/virtualModuleModernEntry.js")
|
206
388
|
)).replaceAll(`'{{storiesFilename}}'`, `'./${storiesFilename}'`).replaceAll(
|
@@ -212,7 +394,7 @@ var getVirtualModules = async (options) => {
|
|
212
394
|
).replace(/\\/g, "\\\\");
|
213
395
|
entries.push(configEntryPath);
|
214
396
|
for (const [key, value] of Object.entries(virtualModules)) {
|
215
|
-
|
397
|
+
import_node_fs4.default.writeFileSync(key, value);
|
216
398
|
}
|
217
399
|
return {
|
218
400
|
virtualModules,
|
@@ -287,7 +469,7 @@ function importPipeline() {
|
|
287
469
|
}
|
288
470
|
|
289
471
|
// src/preview/iframe-rsbuild.config.ts
|
290
|
-
var getAbsolutePath = (input) => (0,
|
472
|
+
var getAbsolutePath = (input) => (0, import_node_path7.dirname)(require.resolve((0, import_node_path7.join)(input, "package.json")));
|
291
473
|
var maybeGetAbsolutePath = (input) => {
|
292
474
|
try {
|
293
475
|
return getAbsolutePath(input);
|
@@ -313,7 +495,7 @@ var iframe_rsbuild_config_default = async (options, extraWebpackConfig) => {
|
|
313
495
|
const { rsbuildConfigPath, addonDocs } = await (0, import_common2.getBuilderOptions)(options);
|
314
496
|
const appliedDocsWebpack = await (0, import_preset.webpack)({}, { ...options, ...addonDocs });
|
315
497
|
const {
|
316
|
-
outputDir = (0,
|
498
|
+
outputDir = (0, import_node_path7.join)(".", "public"),
|
317
499
|
quiet,
|
318
500
|
packageJson,
|
319
501
|
configType,
|
@@ -429,7 +611,7 @@ var iframe_rsbuild_config_default = async (options, extraWebpackConfig) => {
|
|
429
611
|
css: !options.build?.test?.disableSourcemaps
|
430
612
|
},
|
431
613
|
distPath: {
|
432
|
-
root: (0,
|
614
|
+
root: (0, import_node_path7.resolve)(process.cwd(), outputDir)
|
433
615
|
},
|
434
616
|
filename: {
|
435
617
|
js: isProd ? "[name].[contenthash:8].iframe.bundle.js" : "[name].iframe.bundle.js",
|
@@ -612,7 +794,7 @@ var iframe_rsbuild_config_default = async (options, extraWebpackConfig) => {
|
|
612
794
|
|
613
795
|
// src/react-shims.ts
|
614
796
|
var import_promises = require("fs/promises");
|
615
|
-
var
|
797
|
+
var import_node_path8 = require("path");
|
616
798
|
var getIsReactVersion18or19 = async (options) => {
|
617
799
|
const { legacyRootApi } = await options.presets.apply(
|
618
800
|
"frameworkOptions"
|
@@ -625,12 +807,12 @@ var getIsReactVersion18or19 = async (options) => {
|
|
625
807
|
{}
|
626
808
|
);
|
627
809
|
let reactDom = "";
|
628
|
-
reactDom = resolvedReact.reactDom || (0,
|
629
|
-
if (!(0,
|
810
|
+
reactDom = resolvedReact.reactDom || (0, import_node_path8.dirname)(require.resolve("react-dom/package.json"));
|
811
|
+
if (!(0, import_node_path8.isAbsolute)(reactDom)) {
|
630
812
|
return false;
|
631
813
|
}
|
632
814
|
const { version } = JSON.parse(
|
633
|
-
await (0, import_promises.readFile)((0,
|
815
|
+
await (0, import_promises.readFile)((0, import_node_path8.join)(reactDom, "package.json"), "utf-8")
|
634
816
|
);
|
635
817
|
return version.startsWith("18") || version.startsWith("19") || version.startsWith("0.0.0");
|
636
818
|
};
|
@@ -649,7 +831,7 @@ var applyReactShims = async (config, options) => {
|
|
649
831
|
};
|
650
832
|
|
651
833
|
// src/index.ts
|
652
|
-
var corePath = (0,
|
834
|
+
var corePath = (0, import_node_path9.dirname)(require.resolve("storybook/package.json"));
|
653
835
|
var printDuration = (startTime) => (0, import_pretty_hrtime.default)(process.hrtime(startTime)).replace(" ms", " milliseconds").replace(" s", " seconds").replace(" m", " minutes");
|
654
836
|
var executor = {
|
655
837
|
get: async (options) => {
|
@@ -757,7 +939,7 @@ var start = async ({
|
|
757
939
|
error: new Error("Missing Rsbuild build instance at runtime!")
|
758
940
|
});
|
759
941
|
}
|
760
|
-
const previewResolvedDir = (0,
|
942
|
+
const previewResolvedDir = (0, import_node_path9.join)(corePath, "dist/preview");
|
761
943
|
const previewDirOrigin = previewResolvedDir;
|
762
944
|
router.use(
|
763
945
|
"/sb-preview",
|
@@ -780,16 +962,16 @@ var build = async ({ options }) => {
|
|
780
962
|
cwd: process.cwd(),
|
781
963
|
rsbuildConfig: config
|
782
964
|
});
|
783
|
-
const previewResolvedDir = (0,
|
965
|
+
const previewResolvedDir = (0, import_node_path9.join)(corePath, "dist/preview");
|
784
966
|
const previewDirOrigin = previewResolvedDir;
|
785
|
-
const previewDirTarget = (0,
|
967
|
+
const previewDirTarget = (0, import_node_path9.join)(options.outputDir || "", "sb-preview");
|
786
968
|
let stats;
|
787
969
|
rsbuildBuild.onAfterBuild((params) => {
|
788
970
|
stats = params.stats;
|
789
971
|
});
|
790
972
|
const previewFiles = import_fs_extra.default.copy(previewDirOrigin, previewDirTarget, {
|
791
973
|
filter: (src) => {
|
792
|
-
const { ext } = (0,
|
974
|
+
const { ext } = (0, import_node_path9.parse)(src);
|
793
975
|
if (ext) {
|
794
976
|
return ext === ".js";
|
795
977
|
}
|
@@ -803,7 +985,7 @@ var build = async ({ options }) => {
|
|
803
985
|
await close();
|
804
986
|
return stats;
|
805
987
|
};
|
806
|
-
var corePresets = [(0,
|
988
|
+
var corePresets = [(0, import_node_path9.join)(__dirname, "./preview-preset.js")];
|
807
989
|
var previewMainTemplate = () => require.resolve("storybook-builder-rsbuild/templates/preview.ejs");
|
808
990
|
function getRandomPort(host) {
|
809
991
|
return new Promise((resolve3, reject) => {
|
package/dist/index.mjs
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
import { __commonJS,
|
1
|
+
import { __commonJS, __require, __toESM } from './chunk-TTFRSOOU.mjs';
|
2
2
|
import { createServer } from 'net';
|
3
|
-
import
|
3
|
+
import path4, { dirname, join, resolve, parse, isAbsolute } from 'path';
|
4
4
|
import * as rsbuildReal from '@rsbuild/core';
|
5
5
|
import { loadConfig, mergeRsbuildConfig } from '@rsbuild/core';
|
6
|
-
import
|
6
|
+
import fs4 from 'fs-extra';
|
7
7
|
import sirv from 'sirv';
|
8
8
|
import { normalizeStories, loadPreviewOrConfigFile, getBuilderOptions, readTemplate, resolveAddonName, getPresets, stringifyProcessEnvs, isPreservingSymlinks } from 'storybook/internal/common';
|
9
9
|
import { WebpackInvocationError } from 'storybook/internal/server-errors';
|
@@ -13,9 +13,10 @@ import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin';
|
|
13
13
|
import { pluginHtmlMinifierTerser } from 'rsbuild-plugin-html-minifier-terser';
|
14
14
|
import { globalsNameReferenceMap } from 'storybook/internal/preview/globals';
|
15
15
|
import { dedent } from 'ts-dedent';
|
16
|
-
import
|
16
|
+
import fs2 from 'fs';
|
17
17
|
import { webpackIncludeRegexp } from '@storybook/core-webpack';
|
18
|
-
import
|
18
|
+
import process2 from 'process';
|
19
|
+
import { fileURLToPath } from 'url';
|
19
20
|
import { readFile } from 'fs/promises';
|
20
21
|
|
21
22
|
// ../../node_modules/.pnpm/pretty-hrtime@1.0.3/node_modules/pretty-hrtime/index.js
|
@@ -89,20 +90,183 @@ var require_pretty_hrtime = __commonJS({
|
|
89
90
|
}
|
90
91
|
});
|
91
92
|
|
93
|
+
// ../../node_modules/.pnpm/common-path-prefix@3.0.0/node_modules/common-path-prefix/index.js
|
94
|
+
var require_common_path_prefix = __commonJS({
|
95
|
+
"../../node_modules/.pnpm/common-path-prefix@3.0.0/node_modules/common-path-prefix/index.js"(exports, module) {
|
96
|
+
var { sep: DEFAULT_SEPARATOR } = __require("path");
|
97
|
+
var determineSeparator = (paths) => {
|
98
|
+
for (const path6 of paths) {
|
99
|
+
const match = /(\/|\\)/.exec(path6);
|
100
|
+
if (match !== null)
|
101
|
+
return match[0];
|
102
|
+
}
|
103
|
+
return DEFAULT_SEPARATOR;
|
104
|
+
};
|
105
|
+
module.exports = function commonPathPrefix2(paths, sep = determineSeparator(paths)) {
|
106
|
+
const [first = "", ...remaining] = paths;
|
107
|
+
if (first === "" || remaining.length === 0)
|
108
|
+
return "";
|
109
|
+
const parts = first.split(sep);
|
110
|
+
let endOfPrefix = parts.length;
|
111
|
+
for (const path6 of remaining) {
|
112
|
+
const compare = path6.split(sep);
|
113
|
+
for (let i = 0; i < endOfPrefix; i++) {
|
114
|
+
if (compare[i] !== parts[i]) {
|
115
|
+
endOfPrefix = i;
|
116
|
+
}
|
117
|
+
}
|
118
|
+
if (endOfPrefix === 0)
|
119
|
+
return "";
|
120
|
+
}
|
121
|
+
const prefix = parts.slice(0, endOfPrefix).join(sep);
|
122
|
+
return prefix.endsWith(sep) ? prefix : prefix + sep;
|
123
|
+
};
|
124
|
+
}
|
125
|
+
});
|
126
|
+
|
92
127
|
// src/index.ts
|
93
128
|
var import_pretty_hrtime = __toESM(require_pretty_hrtime());
|
94
129
|
|
130
|
+
// ../../node_modules/.pnpm/find-cache-dir@5.0.0/node_modules/find-cache-dir/index.js
|
131
|
+
var import_common_path_prefix = __toESM(require_common_path_prefix(), 1);
|
132
|
+
var typeMappings = {
|
133
|
+
directory: "isDirectory",
|
134
|
+
file: "isFile"
|
135
|
+
};
|
136
|
+
function checkType(type) {
|
137
|
+
if (Object.hasOwnProperty.call(typeMappings, type)) {
|
138
|
+
return;
|
139
|
+
}
|
140
|
+
throw new Error(`Invalid type specified: ${type}`);
|
141
|
+
}
|
142
|
+
var matchType = (type, stat) => stat[typeMappings[type]]();
|
143
|
+
var toPath = (urlOrPath) => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;
|
144
|
+
function locatePathSync(paths, {
|
145
|
+
cwd: cwd2 = process2.cwd(),
|
146
|
+
type = "file",
|
147
|
+
allowSymlinks = true
|
148
|
+
} = {}) {
|
149
|
+
checkType(type);
|
150
|
+
cwd2 = toPath(cwd2);
|
151
|
+
const statFunction = allowSymlinks ? fs2.statSync : fs2.lstatSync;
|
152
|
+
for (const path_ of paths) {
|
153
|
+
try {
|
154
|
+
const stat = statFunction(path4.resolve(cwd2, path_), {
|
155
|
+
throwIfNoEntry: false
|
156
|
+
});
|
157
|
+
if (!stat) {
|
158
|
+
continue;
|
159
|
+
}
|
160
|
+
if (matchType(type, stat)) {
|
161
|
+
return path_;
|
162
|
+
}
|
163
|
+
} catch {
|
164
|
+
}
|
165
|
+
}
|
166
|
+
}
|
167
|
+
|
168
|
+
// ../../node_modules/.pnpm/find-up@6.3.0/node_modules/find-up/index.js
|
169
|
+
var toPath2 = (urlOrPath) => urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;
|
170
|
+
var findUpStop = Symbol("findUpStop");
|
171
|
+
function findUpMultipleSync(name, options = {}) {
|
172
|
+
let directory = path4.resolve(toPath2(options.cwd) || "");
|
173
|
+
const { root } = path4.parse(directory);
|
174
|
+
const stopAt = options.stopAt || root;
|
175
|
+
const limit = options.limit || Number.POSITIVE_INFINITY;
|
176
|
+
const paths = [name].flat();
|
177
|
+
const runMatcher = (locateOptions) => {
|
178
|
+
if (typeof name !== "function") {
|
179
|
+
return locatePathSync(paths, locateOptions);
|
180
|
+
}
|
181
|
+
const foundPath = name(locateOptions.cwd);
|
182
|
+
if (typeof foundPath === "string") {
|
183
|
+
return locatePathSync([foundPath], locateOptions);
|
184
|
+
}
|
185
|
+
return foundPath;
|
186
|
+
};
|
187
|
+
const matches = [];
|
188
|
+
while (true) {
|
189
|
+
const foundPath = runMatcher({ ...options, cwd: directory });
|
190
|
+
if (foundPath === findUpStop) {
|
191
|
+
break;
|
192
|
+
}
|
193
|
+
if (foundPath) {
|
194
|
+
matches.push(path4.resolve(directory, foundPath));
|
195
|
+
}
|
196
|
+
if (directory === stopAt || matches.length >= limit) {
|
197
|
+
break;
|
198
|
+
}
|
199
|
+
directory = path4.dirname(directory);
|
200
|
+
}
|
201
|
+
return matches;
|
202
|
+
}
|
203
|
+
function findUpSync(name, options = {}) {
|
204
|
+
const matches = findUpMultipleSync(name, { ...options, limit: 1 });
|
205
|
+
return matches[0];
|
206
|
+
}
|
207
|
+
|
208
|
+
// ../../node_modules/.pnpm/pkg-dir@7.0.0/node_modules/pkg-dir/index.js
|
209
|
+
function packageDirectorySync({ cwd: cwd2 } = {}) {
|
210
|
+
const filePath = findUpSync("package.json", { cwd: cwd2 });
|
211
|
+
return filePath && path4.dirname(filePath);
|
212
|
+
}
|
213
|
+
|
214
|
+
// ../../node_modules/.pnpm/find-cache-dir@5.0.0/node_modules/find-cache-dir/index.js
|
215
|
+
var { env, cwd } = process2;
|
216
|
+
var isWritable = (path6) => {
|
217
|
+
try {
|
218
|
+
fs2.accessSync(path6, fs2.constants.W_OK);
|
219
|
+
return true;
|
220
|
+
} catch {
|
221
|
+
return false;
|
222
|
+
}
|
223
|
+
};
|
224
|
+
function useDirectory(directory, options) {
|
225
|
+
if (options.create) {
|
226
|
+
fs2.mkdirSync(directory, { recursive: true });
|
227
|
+
}
|
228
|
+
return directory;
|
229
|
+
}
|
230
|
+
function getNodeModuleDirectory(directory) {
|
231
|
+
const nodeModules = path4.join(directory, "node_modules");
|
232
|
+
if (!isWritable(nodeModules) && (fs2.existsSync(nodeModules) || !isWritable(path4.join(directory)))) {
|
233
|
+
return;
|
234
|
+
}
|
235
|
+
return nodeModules;
|
236
|
+
}
|
237
|
+
function findCacheDirectory(options = {}) {
|
238
|
+
if (env.CACHE_DIR && !["true", "false", "1", "0"].includes(env.CACHE_DIR)) {
|
239
|
+
return useDirectory(path4.join(env.CACHE_DIR, options.name), options);
|
240
|
+
}
|
241
|
+
let { cwd: directory = cwd(), files } = options;
|
242
|
+
if (files) {
|
243
|
+
if (!Array.isArray(files)) {
|
244
|
+
throw new TypeError(`Expected \`files\` option to be an array, got \`${typeof files}\`.`);
|
245
|
+
}
|
246
|
+
directory = (0, import_common_path_prefix.default)(files.map((file) => path4.resolve(directory, file)));
|
247
|
+
}
|
248
|
+
directory = packageDirectorySync({ cwd: directory });
|
249
|
+
if (!directory) {
|
250
|
+
return;
|
251
|
+
}
|
252
|
+
const nodeModules = getNodeModuleDirectory(directory);
|
253
|
+
if (!nodeModules) {
|
254
|
+
return;
|
255
|
+
}
|
256
|
+
return useDirectory(path4.join(directory, "node_modules", ".cache", options.name), options);
|
257
|
+
}
|
258
|
+
|
95
259
|
// ../../node_modules/.pnpm/slash@5.1.0/node_modules/slash/index.js
|
96
|
-
function slash(
|
97
|
-
const isExtendedLengthPath =
|
260
|
+
function slash(path6) {
|
261
|
+
const isExtendedLengthPath = path6.startsWith("\\\\?\\");
|
98
262
|
if (isExtendedLengthPath) {
|
99
|
-
return
|
263
|
+
return path6;
|
100
264
|
}
|
101
|
-
return
|
265
|
+
return path6.replace(/\\/g, "/");
|
102
266
|
}
|
103
267
|
var getVirtualModules = async (options) => {
|
104
268
|
const virtualModules = {};
|
105
|
-
const
|
269
|
+
const cwd2 = process.cwd();
|
106
270
|
const workingDir = options.cache ? (
|
107
271
|
// TODO: This is a hard code cache dir, as Rspack doesn't support virtual modules now.
|
108
272
|
// Remove this when Rspack supports virtual modules.
|
@@ -111,8 +275,8 @@ var getVirtualModules = async (options) => {
|
|
111
275
|
create: true
|
112
276
|
})
|
113
277
|
) : process.cwd();
|
114
|
-
if (!
|
115
|
-
|
278
|
+
if (!fs2.existsSync(workingDir)) {
|
279
|
+
fs2.mkdirSync(workingDir, { recursive: true });
|
116
280
|
}
|
117
281
|
const isProd = options.configType === "PRODUCTION";
|
118
282
|
const nonNormalizedStories = await options.presets.apply("stories", []);
|
@@ -121,7 +285,7 @@ var getVirtualModules = async (options) => {
|
|
121
285
|
configDir: options.configDir,
|
122
286
|
workingDir
|
123
287
|
});
|
124
|
-
const realPathRelativeToCwd =
|
288
|
+
const realPathRelativeToCwd = path4.relative(workingDir, cwd2).split(path4.sep).join(path4.posix.sep);
|
125
289
|
const previewAnnotations = [
|
126
290
|
...(await options.presets.apply(
|
127
291
|
"previewAnnotations",
|
@@ -156,7 +320,7 @@ var getVirtualModules = async (options) => {
|
|
156
320
|
).replace(/\\/g, "\\\\");
|
157
321
|
entries.push(configEntryPath);
|
158
322
|
for (const [key, value] of Object.entries(virtualModules)) {
|
159
|
-
|
323
|
+
fs2.writeFileSync(key, value);
|
160
324
|
}
|
161
325
|
return {
|
162
326
|
virtualModules,
|
@@ -729,7 +893,7 @@ var build = async ({ options }) => {
|
|
729
893
|
rsbuildBuild.onAfterBuild((params) => {
|
730
894
|
stats = params.stats;
|
731
895
|
});
|
732
|
-
const previewFiles =
|
896
|
+
const previewFiles = fs4.copy(previewDirOrigin, previewDirTarget, {
|
733
897
|
filter: (src) => {
|
734
898
|
const { ext } = parse(src);
|
735
899
|
if (ext) {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "storybook-builder-rsbuild",
|
3
|
-
"version": "2.0.
|
3
|
+
"version": "2.0.4",
|
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.7.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,9 +82,10 @@
|
|
83
82
|
"@types/fs-extra": "^11.0.4",
|
84
83
|
"@types/node": "^18.19.110",
|
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
|
-
"storybook": "9.
|
88
|
+
"storybook": "9.1.2",
|
89
89
|
"typescript": "^5.8.3"
|
90
90
|
},
|
91
91
|
"peerDependencies": {
|