storybook-builder-rsbuild 2.0.2 → 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 +255 -45
- package/dist/index.mjs +221 -29
- package/package.json +7 -7
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,
|
@@ -416,8 +598,6 @@ var iframe_rsbuild_config_default = async (options, extraWebpackConfig) => {
|
|
416
598
|
} else {
|
417
599
|
contentFromConfig = content;
|
418
600
|
}
|
419
|
-
contentFromConfig.source ??= {};
|
420
|
-
contentFromConfig.source.entry = {};
|
421
601
|
const resourceFilename = isProd ? "static/media/[name].[contenthash:8][ext]" : "static/media/[path][name][ext]";
|
422
602
|
const rsbuildConfig = (0, import_core.mergeRsbuildConfig)(contentFromConfig, {
|
423
603
|
output: {
|
@@ -431,7 +611,7 @@ var iframe_rsbuild_config_default = async (options, extraWebpackConfig) => {
|
|
431
611
|
css: !options.build?.test?.disableSourcemaps
|
432
612
|
},
|
433
613
|
distPath: {
|
434
|
-
root: (0,
|
614
|
+
root: (0, import_node_path7.resolve)(process.cwd(), outputDir)
|
435
615
|
},
|
436
616
|
filename: {
|
437
617
|
js: isProd ? "[name].[contenthash:8].iframe.bundle.js" : "[name].iframe.bundle.js",
|
@@ -459,10 +639,6 @@ var iframe_rsbuild_config_default = async (options, extraWebpackConfig) => {
|
|
459
639
|
// TODO: Rspack doesn't support virtual modules yet, use cache dir instead
|
460
640
|
// we needed to explicitly set the module in `node_modules` to be compiled
|
461
641
|
include: [/[\\/]node_modules[\\/].*[\\/]storybook-config-entry\.js/],
|
462
|
-
entry: {
|
463
|
-
// to avoid `It's not allowed to load an initial chunk on demand. The chunk name "main" is already used by an entrypoint` of
|
464
|
-
main: [...entries ?? [], ...dynamicEntries]
|
465
|
-
},
|
466
642
|
define: {
|
467
643
|
...(0, import_common2.stringifyProcessEnvs)(envs),
|
468
644
|
NODE_ENV: JSON.stringify(process.env.NODE_ENV)
|
@@ -486,7 +662,41 @@ var iframe_rsbuild_config_default = async (options, extraWebpackConfig) => {
|
|
486
662
|
removeScriptTypeAttributes: false,
|
487
663
|
removeStyleLinkTypeAttributes: true,
|
488
664
|
useShortDoctype: true
|
489
|
-
}))
|
665
|
+
})),
|
666
|
+
{
|
667
|
+
name: "storybook-config-entry",
|
668
|
+
setup: (api) => {
|
669
|
+
api.modifyEnvironmentConfig({
|
670
|
+
handler: (config, { mergeEnvironmentConfig }) => {
|
671
|
+
const baseConfig = { ...config };
|
672
|
+
delete baseConfig.source.entry;
|
673
|
+
return mergeEnvironmentConfig(config, {
|
674
|
+
// Reset `config.source.entry` field, do not use provided entry
|
675
|
+
// see https://github.com/rspack-contrib/storybook-rsbuild/issues/43
|
676
|
+
source: {
|
677
|
+
entry: {
|
678
|
+
main: [...entries ?? [], ...dynamicEntries]
|
679
|
+
}
|
680
|
+
},
|
681
|
+
tools: {
|
682
|
+
rspack: {
|
683
|
+
experiments: {
|
684
|
+
outputModule: false
|
685
|
+
},
|
686
|
+
externalsType: "var",
|
687
|
+
output: {
|
688
|
+
module: false,
|
689
|
+
chunkFormat: "array-push",
|
690
|
+
chunkLoading: "jsonp"
|
691
|
+
}
|
692
|
+
}
|
693
|
+
}
|
694
|
+
});
|
695
|
+
},
|
696
|
+
order: "post"
|
697
|
+
});
|
698
|
+
}
|
699
|
+
}
|
490
700
|
].filter(Boolean),
|
491
701
|
tools: {
|
492
702
|
rspack: (config, { addRules, appendPlugins, rspack, mergeConfig }) => {
|
@@ -584,7 +794,7 @@ var iframe_rsbuild_config_default = async (options, extraWebpackConfig) => {
|
|
584
794
|
|
585
795
|
// src/react-shims.ts
|
586
796
|
var import_promises = require("fs/promises");
|
587
|
-
var
|
797
|
+
var import_node_path8 = require("path");
|
588
798
|
var getIsReactVersion18or19 = async (options) => {
|
589
799
|
const { legacyRootApi } = await options.presets.apply(
|
590
800
|
"frameworkOptions"
|
@@ -597,12 +807,12 @@ var getIsReactVersion18or19 = async (options) => {
|
|
597
807
|
{}
|
598
808
|
);
|
599
809
|
let reactDom = "";
|
600
|
-
reactDom = resolvedReact.reactDom || (0,
|
601
|
-
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)) {
|
602
812
|
return false;
|
603
813
|
}
|
604
814
|
const { version } = JSON.parse(
|
605
|
-
await (0, import_promises.readFile)((0,
|
815
|
+
await (0, import_promises.readFile)((0, import_node_path8.join)(reactDom, "package.json"), "utf-8")
|
606
816
|
);
|
607
817
|
return version.startsWith("18") || version.startsWith("19") || version.startsWith("0.0.0");
|
608
818
|
};
|
@@ -621,7 +831,7 @@ var applyReactShims = async (config, options) => {
|
|
621
831
|
};
|
622
832
|
|
623
833
|
// src/index.ts
|
624
|
-
var corePath = (0,
|
834
|
+
var corePath = (0, import_node_path9.dirname)(require.resolve("storybook/package.json"));
|
625
835
|
var printDuration = (startTime) => (0, import_pretty_hrtime.default)(process.hrtime(startTime)).replace(" ms", " milliseconds").replace(" s", " seconds").replace(" m", " minutes");
|
626
836
|
var executor = {
|
627
837
|
get: async (options) => {
|
@@ -664,18 +874,18 @@ var rsbuild = async (_, options) => {
|
|
664
874
|
},
|
665
875
|
options
|
666
876
|
);
|
667
|
-
let
|
668
|
-
const shimsConfig = await applyReactShims(
|
669
|
-
|
670
|
-
|
877
|
+
let intrinsicRsbuildConfig = await iframe_rsbuild_config_default(options, webpackAddonsConfig);
|
878
|
+
const shimsConfig = await applyReactShims(intrinsicRsbuildConfig, options);
|
879
|
+
intrinsicRsbuildConfig = rsbuildReal.mergeRsbuildConfig(
|
880
|
+
intrinsicRsbuildConfig,
|
671
881
|
shimsConfig
|
672
882
|
);
|
673
|
-
const
|
883
|
+
const finalConfig = await presets.apply(
|
674
884
|
"rsbuildFinal",
|
675
|
-
|
885
|
+
intrinsicRsbuildConfig,
|
676
886
|
options
|
677
887
|
);
|
678
|
-
return
|
888
|
+
return finalConfig;
|
679
889
|
};
|
680
890
|
var getConfig = async (options) => {
|
681
891
|
const { presets } = options;
|
@@ -729,7 +939,7 @@ var start = async ({
|
|
729
939
|
error: new Error("Missing Rsbuild build instance at runtime!")
|
730
940
|
});
|
731
941
|
}
|
732
|
-
const previewResolvedDir = (0,
|
942
|
+
const previewResolvedDir = (0, import_node_path9.join)(corePath, "dist/preview");
|
733
943
|
const previewDirOrigin = previewResolvedDir;
|
734
944
|
router.use(
|
735
945
|
"/sb-preview",
|
@@ -752,16 +962,16 @@ var build = async ({ options }) => {
|
|
752
962
|
cwd: process.cwd(),
|
753
963
|
rsbuildConfig: config
|
754
964
|
});
|
755
|
-
const previewResolvedDir = (0,
|
965
|
+
const previewResolvedDir = (0, import_node_path9.join)(corePath, "dist/preview");
|
756
966
|
const previewDirOrigin = previewResolvedDir;
|
757
|
-
const previewDirTarget = (0,
|
967
|
+
const previewDirTarget = (0, import_node_path9.join)(options.outputDir || "", "sb-preview");
|
758
968
|
let stats;
|
759
969
|
rsbuildBuild.onAfterBuild((params) => {
|
760
970
|
stats = params.stats;
|
761
971
|
});
|
762
972
|
const previewFiles = import_fs_extra.default.copy(previewDirOrigin, previewDirTarget, {
|
763
973
|
filter: (src) => {
|
764
|
-
const { ext } = (0,
|
974
|
+
const { ext } = (0, import_node_path9.parse)(src);
|
765
975
|
if (ext) {
|
766
976
|
return ext === ".js";
|
767
977
|
}
|
@@ -775,7 +985,7 @@ var build = async ({ options }) => {
|
|
775
985
|
await close();
|
776
986
|
return stats;
|
777
987
|
};
|
778
|
-
var corePresets = [(0,
|
988
|
+
var corePresets = [(0, import_node_path9.join)(__dirname, "./preview-preset.js")];
|
779
989
|
var previewMainTemplate = () => require.resolve("storybook-builder-rsbuild/templates/preview.ejs");
|
780
990
|
function getRandomPort(host) {
|
781
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,
|
@@ -360,8 +524,6 @@ var iframe_rsbuild_config_default = async (options, extraWebpackConfig) => {
|
|
360
524
|
} else {
|
361
525
|
contentFromConfig = content;
|
362
526
|
}
|
363
|
-
contentFromConfig.source ??= {};
|
364
|
-
contentFromConfig.source.entry = {};
|
365
527
|
const resourceFilename = isProd ? "static/media/[name].[contenthash:8][ext]" : "static/media/[path][name][ext]";
|
366
528
|
const rsbuildConfig = mergeRsbuildConfig(contentFromConfig, {
|
367
529
|
output: {
|
@@ -403,10 +565,6 @@ var iframe_rsbuild_config_default = async (options, extraWebpackConfig) => {
|
|
403
565
|
// TODO: Rspack doesn't support virtual modules yet, use cache dir instead
|
404
566
|
// we needed to explicitly set the module in `node_modules` to be compiled
|
405
567
|
include: [/[\\/]node_modules[\\/].*[\\/]storybook-config-entry\.js/],
|
406
|
-
entry: {
|
407
|
-
// to avoid `It's not allowed to load an initial chunk on demand. The chunk name "main" is already used by an entrypoint` of
|
408
|
-
main: [...entries ?? [], ...dynamicEntries]
|
409
|
-
},
|
410
568
|
define: {
|
411
569
|
...stringifyProcessEnvs(envs),
|
412
570
|
NODE_ENV: JSON.stringify(process.env.NODE_ENV)
|
@@ -430,7 +588,41 @@ var iframe_rsbuild_config_default = async (options, extraWebpackConfig) => {
|
|
430
588
|
removeScriptTypeAttributes: false,
|
431
589
|
removeStyleLinkTypeAttributes: true,
|
432
590
|
useShortDoctype: true
|
433
|
-
}))
|
591
|
+
})),
|
592
|
+
{
|
593
|
+
name: "storybook-config-entry",
|
594
|
+
setup: (api) => {
|
595
|
+
api.modifyEnvironmentConfig({
|
596
|
+
handler: (config, { mergeEnvironmentConfig }) => {
|
597
|
+
const baseConfig = { ...config };
|
598
|
+
delete baseConfig.source.entry;
|
599
|
+
return mergeEnvironmentConfig(config, {
|
600
|
+
// Reset `config.source.entry` field, do not use provided entry
|
601
|
+
// see https://github.com/rspack-contrib/storybook-rsbuild/issues/43
|
602
|
+
source: {
|
603
|
+
entry: {
|
604
|
+
main: [...entries ?? [], ...dynamicEntries]
|
605
|
+
}
|
606
|
+
},
|
607
|
+
tools: {
|
608
|
+
rspack: {
|
609
|
+
experiments: {
|
610
|
+
outputModule: false
|
611
|
+
},
|
612
|
+
externalsType: "var",
|
613
|
+
output: {
|
614
|
+
module: false,
|
615
|
+
chunkFormat: "array-push",
|
616
|
+
chunkLoading: "jsonp"
|
617
|
+
}
|
618
|
+
}
|
619
|
+
}
|
620
|
+
});
|
621
|
+
},
|
622
|
+
order: "post"
|
623
|
+
});
|
624
|
+
}
|
625
|
+
}
|
434
626
|
].filter(Boolean),
|
435
627
|
tools: {
|
436
628
|
rspack: (config, { addRules, appendPlugins, rspack, mergeConfig }) => {
|
@@ -606,18 +798,18 @@ var rsbuild = async (_, options) => {
|
|
606
798
|
},
|
607
799
|
options
|
608
800
|
);
|
609
|
-
let
|
610
|
-
const shimsConfig = await applyReactShims(
|
611
|
-
|
612
|
-
|
801
|
+
let intrinsicRsbuildConfig = await iframe_rsbuild_config_default(options, webpackAddonsConfig);
|
802
|
+
const shimsConfig = await applyReactShims(intrinsicRsbuildConfig, options);
|
803
|
+
intrinsicRsbuildConfig = rsbuildReal.mergeRsbuildConfig(
|
804
|
+
intrinsicRsbuildConfig,
|
613
805
|
shimsConfig
|
614
806
|
);
|
615
|
-
const
|
807
|
+
const finalConfig = await presets.apply(
|
616
808
|
"rsbuildFinal",
|
617
|
-
|
809
|
+
intrinsicRsbuildConfig,
|
618
810
|
options
|
619
811
|
);
|
620
|
-
return
|
812
|
+
return finalConfig;
|
621
813
|
};
|
622
814
|
var getConfig = async (options) => {
|
623
815
|
const { presets } = options;
|
@@ -701,7 +893,7 @@ var build = async ({ options }) => {
|
|
701
893
|
rsbuildBuild.onAfterBuild((params) => {
|
702
894
|
stats = params.stats;
|
703
895
|
});
|
704
|
-
const previewFiles =
|
896
|
+
const previewFiles = fs4.copy(previewDirOrigin, previewDirTarget, {
|
705
897
|
filter: (src) => {
|
706
898
|
const { ext } = parse(src);
|
707
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",
|
@@ -57,15 +57,14 @@
|
|
57
57
|
"!src/**/*"
|
58
58
|
],
|
59
59
|
"dependencies": {
|
60
|
-
"@rsbuild/plugin-type-check": "^1.2.
|
61
|
-
"@storybook/addon-docs": "^9.0.
|
62
|
-
"@storybook/core-webpack": "^9.0.
|
60
|
+
"@rsbuild/plugin-type-check": "^1.2.3",
|
61
|
+
"@storybook/addon-docs": "^9.0.18",
|
62
|
+
"@storybook/core-webpack": "^9.0.18",
|
63
63
|
"browser-assert": "^1.2.1",
|
64
64
|
"case-sensitive-paths-webpack-plugin": "^2.4.0",
|
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",
|
@@ -78,14 +77,15 @@
|
|
78
77
|
"util-deprecate": "^1.0.2"
|
79
78
|
},
|
80
79
|
"devDependencies": {
|
81
|
-
"@rsbuild/core": "^1.
|
80
|
+
"@rsbuild/core": "^1.4.11",
|
82
81
|
"@types/find-cache-dir": "^5.0.2",
|
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": {
|