storybook-builder-rsbuild 0.0.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +11 -0
- package/dist/chunk-TTFRSOOU.mjs +34 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +627 -0
- package/dist/index.mjs +554 -0
- package/dist/loaders/export-order-loader.d.ts +2 -0
- package/dist/loaders/export-order-loader.js +72 -0
- package/dist/loaders/export-order-loader.mjs +41 -0
- package/dist/presets/custom-rsbuild-preset.d.ts +2 -0
- package/dist/presets/custom-rsbuild-preset.js +56 -0
- package/dist/presets/preview-preset.d.ts +2 -0
- package/dist/presets/preview-preset.js +427 -0
- package/dist/preview-preset.d.ts +2 -0
- package/dist/preview-preset.js +42 -0
- package/package.json +112 -0
- package/templates/preview.ejs +54 -0
- package/templates/virtualModuleModernEntry.js.handlebars +34 -0
- package/typings.d.ts +2 -0
package/dist/index.mjs
ADDED
@@ -0,0 +1,554 @@
|
|
1
|
+
import { __commonJS, __toESM, __require } from './chunk-TTFRSOOU.mjs';
|
2
|
+
import * as rsbuildReal from '@rsbuild/core';
|
3
|
+
import { loadConfig, mergeRsbuildConfig } from '@rsbuild/core';
|
4
|
+
import path, { join, resolve, parse, dirname } from 'path';
|
5
|
+
import express from 'express';
|
6
|
+
import fs2 from 'fs-extra';
|
7
|
+
import { WebpackInvocationError, NoStatsForViteDevError } from '@storybook/core-events/server-errors';
|
8
|
+
import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin';
|
9
|
+
import { globalsNameReferenceMap } from '@storybook/preview/globals';
|
10
|
+
import { normalizeStories, loadPreviewOrConfigFile, handlebars, readTemplate, getBuilderOptions, stringifyProcessEnvs, isPreservingSymlinks } from '@storybook/core-common';
|
11
|
+
import { dedent } from 'ts-dedent';
|
12
|
+
import fs from 'fs';
|
13
|
+
import { webpackIncludeRegexp } from '@storybook/core-webpack';
|
14
|
+
import { webpack } from '@storybook/addon-docs/dist/preset';
|
15
|
+
|
16
|
+
// ../../node_modules/.pnpm/pretty-hrtime@1.0.3/node_modules/pretty-hrtime/index.js
|
17
|
+
var require_pretty_hrtime = __commonJS({
|
18
|
+
"../../node_modules/.pnpm/pretty-hrtime@1.0.3/node_modules/pretty-hrtime/index.js"(exports, module) {
|
19
|
+
var minimalDesc = ["h", "min", "s", "ms", "\u03BCs", "ns"];
|
20
|
+
var verboseDesc = ["hour", "minute", "second", "millisecond", "microsecond", "nanosecond"];
|
21
|
+
var convert = [60 * 60, 60, 1, 1e6, 1e3, 1];
|
22
|
+
module.exports = function(source, opts) {
|
23
|
+
var verbose, precise, i, spot, sourceAtStep, valAtStep, decimals, strAtStep, results, totalSeconds;
|
24
|
+
verbose = false;
|
25
|
+
precise = false;
|
26
|
+
if (opts) {
|
27
|
+
verbose = opts.verbose || false;
|
28
|
+
precise = opts.precise || false;
|
29
|
+
}
|
30
|
+
if (!Array.isArray(source) || source.length !== 2) {
|
31
|
+
return "";
|
32
|
+
}
|
33
|
+
if (typeof source[0] !== "number" || typeof source[1] !== "number") {
|
34
|
+
return "";
|
35
|
+
}
|
36
|
+
if (source[1] < 0) {
|
37
|
+
totalSeconds = source[0] + source[1] / 1e9;
|
38
|
+
source[0] = parseInt(totalSeconds);
|
39
|
+
source[1] = parseFloat((totalSeconds % 1).toPrecision(9)) * 1e9;
|
40
|
+
}
|
41
|
+
results = "";
|
42
|
+
for (i = 0; i < 6; i++) {
|
43
|
+
spot = i < 3 ? 0 : 1;
|
44
|
+
sourceAtStep = source[spot];
|
45
|
+
if (i !== 3 && i !== 0) {
|
46
|
+
sourceAtStep = sourceAtStep % convert[i - 1];
|
47
|
+
}
|
48
|
+
if (i === 2) {
|
49
|
+
sourceAtStep += source[1] / 1e9;
|
50
|
+
}
|
51
|
+
valAtStep = sourceAtStep / convert[i];
|
52
|
+
if (valAtStep >= 1) {
|
53
|
+
if (verbose) {
|
54
|
+
valAtStep = Math.floor(valAtStep);
|
55
|
+
}
|
56
|
+
if (!precise) {
|
57
|
+
decimals = valAtStep >= 10 ? 0 : 2;
|
58
|
+
strAtStep = valAtStep.toFixed(decimals);
|
59
|
+
} else {
|
60
|
+
strAtStep = valAtStep.toString();
|
61
|
+
}
|
62
|
+
if (strAtStep.indexOf(".") > -1 && strAtStep[strAtStep.length - 1] === "0") {
|
63
|
+
strAtStep = strAtStep.replace(/\.?0+$/, "");
|
64
|
+
}
|
65
|
+
if (results) {
|
66
|
+
results += " ";
|
67
|
+
}
|
68
|
+
results += strAtStep;
|
69
|
+
if (verbose) {
|
70
|
+
results += " " + verboseDesc[i];
|
71
|
+
if (strAtStep !== "1") {
|
72
|
+
results += "s";
|
73
|
+
}
|
74
|
+
} else {
|
75
|
+
results += " " + minimalDesc[i];
|
76
|
+
}
|
77
|
+
if (!verbose) {
|
78
|
+
break;
|
79
|
+
}
|
80
|
+
}
|
81
|
+
}
|
82
|
+
return results;
|
83
|
+
};
|
84
|
+
}
|
85
|
+
});
|
86
|
+
|
87
|
+
// ../../node_modules/.pnpm/slash@5.1.0/node_modules/slash/index.js
|
88
|
+
function slash(path2) {
|
89
|
+
const isExtendedLengthPath = path2.startsWith("\\\\?\\");
|
90
|
+
if (isExtendedLengthPath) {
|
91
|
+
return path2;
|
92
|
+
}
|
93
|
+
return path2.replace(/\\/g, "/");
|
94
|
+
}
|
95
|
+
var getVirtualModules = async (options) => {
|
96
|
+
const virtualModules = {};
|
97
|
+
const cwd = process.cwd();
|
98
|
+
const workingDir = options.cache?.basePath || process.cwd();
|
99
|
+
const isProd = options.configType === "PRODUCTION";
|
100
|
+
const nonNormalizedStories = await options.presets.apply("stories", []);
|
101
|
+
const entries = [];
|
102
|
+
const stories = normalizeStories(nonNormalizedStories, {
|
103
|
+
configDir: options.configDir,
|
104
|
+
workingDir
|
105
|
+
});
|
106
|
+
const realPathRelativeToCwd = path.relative(workingDir, cwd);
|
107
|
+
const previewAnnotations = [
|
108
|
+
...(await options.presets.apply(
|
109
|
+
"previewAnnotations",
|
110
|
+
[],
|
111
|
+
options
|
112
|
+
)).map((entry) => {
|
113
|
+
if (typeof entry === "object") {
|
114
|
+
return entry.absolute;
|
115
|
+
}
|
116
|
+
return slash(entry);
|
117
|
+
}),
|
118
|
+
loadPreviewOrConfigFile(options)
|
119
|
+
].filter(Boolean);
|
120
|
+
const storiesFilename = "storybook-stories.js";
|
121
|
+
const storiesPath = resolve(join(workingDir, storiesFilename));
|
122
|
+
const needPipelinedImport = !isProd;
|
123
|
+
virtualModules[storiesPath] = toImportFn(stories, realPathRelativeToCwd, {
|
124
|
+
needPipelinedImport
|
125
|
+
});
|
126
|
+
const configEntryPath = resolve(join(workingDir, "storybook-config-entry.js"));
|
127
|
+
virtualModules[configEntryPath] = handlebars(
|
128
|
+
await readTemplate(
|
129
|
+
__require.resolve(
|
130
|
+
"storybook-builder-rsbuild/templates/virtualModuleModernEntry.js.handlebars"
|
131
|
+
)
|
132
|
+
),
|
133
|
+
{
|
134
|
+
storiesFilename,
|
135
|
+
previewAnnotations
|
136
|
+
}
|
137
|
+
// We need to double escape `\` for webpack. We may have some in windows paths
|
138
|
+
).replace(/\\/g, "\\\\");
|
139
|
+
entries.push(configEntryPath);
|
140
|
+
Object.entries(virtualModules).forEach(([key, value]) => {
|
141
|
+
fs.writeFileSync(key, value);
|
142
|
+
});
|
143
|
+
return {
|
144
|
+
virtualModules,
|
145
|
+
entries
|
146
|
+
};
|
147
|
+
};
|
148
|
+
function toImportFnPart(specifier) {
|
149
|
+
const { directory, importPathMatcher } = specifier;
|
150
|
+
return dedent`
|
151
|
+
async (path) => {
|
152
|
+
if (!${importPathMatcher}.exec(path)) {
|
153
|
+
return;
|
154
|
+
}
|
155
|
+
|
156
|
+
const pathRemainder = path.substring(${directory.length + 1});
|
157
|
+
return import(
|
158
|
+
/* webpackChunkName: "[request]" */
|
159
|
+
/* webpackInclude: ${webpackIncludeRegexp(specifier)} */
|
160
|
+
'${directory}/' + pathRemainder
|
161
|
+
);
|
162
|
+
}
|
163
|
+
|
164
|
+
`;
|
165
|
+
}
|
166
|
+
function toImportFn(stories, relativeOffset, { needPipelinedImport } = {}) {
|
167
|
+
let pipelinedImport = `const pipeline = (x) => x();`;
|
168
|
+
if (needPipelinedImport) {
|
169
|
+
pipelinedImport = `
|
170
|
+
const importPipeline = ${importPipeline};
|
171
|
+
const pipeline = importPipeline();
|
172
|
+
`;
|
173
|
+
}
|
174
|
+
return dedent`
|
175
|
+
${pipelinedImport}
|
176
|
+
|
177
|
+
const importers = [
|
178
|
+
${stories.map(toImportFnPart).join(",\n")}
|
179
|
+
];
|
180
|
+
|
181
|
+
export async function importFn(path) {
|
182
|
+
const offset = '${relativeOffset}';
|
183
|
+
|
184
|
+
for (let i = 0; i < importers.length; i++) {
|
185
|
+
const pathWithOffset = buildPath(offset, path)
|
186
|
+
|
187
|
+
const moduleExports = await pipeline(() => importers[i](pathWithOffset));
|
188
|
+
if (moduleExports) {
|
189
|
+
return moduleExports;
|
190
|
+
}
|
191
|
+
}
|
192
|
+
}
|
193
|
+
|
194
|
+
function buildPath(offset, path) {
|
195
|
+
if(path.startsWith('./')) {
|
196
|
+
return offset + '/' + path.substring(2);
|
197
|
+
} else {
|
198
|
+
return offset + '/' + path;
|
199
|
+
}
|
200
|
+
}
|
201
|
+
`;
|
202
|
+
}
|
203
|
+
function importPipeline() {
|
204
|
+
let importGate = Promise.resolve();
|
205
|
+
return async (importFn) => {
|
206
|
+
await importGate;
|
207
|
+
const moduleExportsPromise = importFn();
|
208
|
+
importGate = importGate.then(async () => {
|
209
|
+
await moduleExportsPromise;
|
210
|
+
});
|
211
|
+
return moduleExportsPromise;
|
212
|
+
};
|
213
|
+
}
|
214
|
+
var getAbsolutePath = (input) => dirname(__require.resolve(join(input, "package.json")));
|
215
|
+
var maybeGetAbsolutePath = (input) => {
|
216
|
+
try {
|
217
|
+
return getAbsolutePath(input);
|
218
|
+
} catch (e) {
|
219
|
+
return false;
|
220
|
+
}
|
221
|
+
};
|
222
|
+
var managerAPIPath = maybeGetAbsolutePath(`@storybook/manager-api`);
|
223
|
+
var componentsPath = maybeGetAbsolutePath(`@storybook/components`);
|
224
|
+
var globalPath = maybeGetAbsolutePath(`@storybook/global`);
|
225
|
+
var routerPath = maybeGetAbsolutePath(`@storybook/router`);
|
226
|
+
var themingPath = maybeGetAbsolutePath(`@storybook/theming`);
|
227
|
+
var storybookPaths = {
|
228
|
+
...managerAPIPath ? {
|
229
|
+
[`@storybook/manager-api`]: managerAPIPath
|
230
|
+
} : {},
|
231
|
+
...componentsPath ? { [`@storybook/components`]: componentsPath } : {},
|
232
|
+
...globalPath ? { [`@storybook/global`]: globalPath } : {},
|
233
|
+
...routerPath ? { [`@storybook/router`]: routerPath } : {},
|
234
|
+
...themingPath ? { [`@storybook/theming`]: themingPath } : {}
|
235
|
+
};
|
236
|
+
var iframe_rsbuild_config_default = async (options) => {
|
237
|
+
const appliedDocsWebpack = await webpack({}, options);
|
238
|
+
const {
|
239
|
+
outputDir = join(".", "public"),
|
240
|
+
quiet,
|
241
|
+
packageJson,
|
242
|
+
configType,
|
243
|
+
presets,
|
244
|
+
previewUrl,
|
245
|
+
// typescriptOptions,
|
246
|
+
features
|
247
|
+
} = options;
|
248
|
+
const isProd = configType === "PRODUCTION";
|
249
|
+
const workingDir = process.cwd();
|
250
|
+
const [
|
251
|
+
coreOptions,
|
252
|
+
frameworkOptions,
|
253
|
+
envs,
|
254
|
+
logLevel,
|
255
|
+
headHtmlSnippet,
|
256
|
+
bodyHtmlSnippet,
|
257
|
+
template,
|
258
|
+
docsOptions,
|
259
|
+
entries,
|
260
|
+
nonNormalizedStories,
|
261
|
+
// modulesCount = 1000,
|
262
|
+
build2,
|
263
|
+
tagsOptions
|
264
|
+
] = await Promise.all([
|
265
|
+
presets.apply("core"),
|
266
|
+
presets.apply("frameworkOptions"),
|
267
|
+
presets.apply("env"),
|
268
|
+
presets.apply("logLevel", void 0),
|
269
|
+
presets.apply("previewHead"),
|
270
|
+
presets.apply("previewBody"),
|
271
|
+
presets.apply("previewMainTemplate"),
|
272
|
+
presets.apply("docs"),
|
273
|
+
presets.apply("entries", []),
|
274
|
+
presets.apply("stories", []),
|
275
|
+
options.cache?.get("modulesCount").catch(() => {
|
276
|
+
}),
|
277
|
+
options.presets.apply("build"),
|
278
|
+
presets.apply("tags", {})
|
279
|
+
]);
|
280
|
+
const { rsbuildConfigPath } = await getBuilderOptions(options);
|
281
|
+
const stories = normalizeStories(nonNormalizedStories, {
|
282
|
+
configDir: options.configDir,
|
283
|
+
workingDir
|
284
|
+
});
|
285
|
+
if (!template) {
|
286
|
+
throw new Error(dedent`
|
287
|
+
Storybook's Webpack5 builder requires a template to be specified.
|
288
|
+
Somehow you've ended up with a falsy value for the template option.
|
289
|
+
|
290
|
+
Please file an issue at https://github.com/storybookjs/storybook with a reproduction.
|
291
|
+
`);
|
292
|
+
}
|
293
|
+
const externals = globalsNameReferenceMap;
|
294
|
+
if (build2?.test?.disableBlocks) {
|
295
|
+
externals["@storybook/blocks"] = "__STORYBOOK_BLOCKS_EMPTY_MODULE__";
|
296
|
+
}
|
297
|
+
const { virtualModules: _virtualModules, entries: dynamicEntries } = await getVirtualModules(options);
|
298
|
+
if (!options.cache) {
|
299
|
+
throw new Error("Cache is required");
|
300
|
+
}
|
301
|
+
const { content } = await loadConfig({
|
302
|
+
cwd: workingDir,
|
303
|
+
path: rsbuildConfigPath
|
304
|
+
});
|
305
|
+
const resourceFilename = isProd ? "static/media/[name].[contenthash:8][ext]" : "static/media/[path][name][ext]";
|
306
|
+
const merged = mergeRsbuildConfig(content, {
|
307
|
+
output: {
|
308
|
+
cleanDistPath: false,
|
309
|
+
dataUriLimit: {
|
310
|
+
media: 1e4
|
311
|
+
},
|
312
|
+
sourceMap: {
|
313
|
+
js: options.build?.test?.disableSourcemaps ? false : "cheap-module-source-map",
|
314
|
+
css: options.build?.test?.disableSourcemaps ? false : true
|
315
|
+
},
|
316
|
+
distPath: {
|
317
|
+
root: resolve(process.cwd(), outputDir)
|
318
|
+
},
|
319
|
+
filename: {
|
320
|
+
js: isProd ? "[name].[contenthash:8].iframe.bundle.js" : "[name].iframe.bundle.js",
|
321
|
+
image: resourceFilename,
|
322
|
+
font: resourceFilename,
|
323
|
+
media: resourceFilename
|
324
|
+
},
|
325
|
+
assetPrefix: "/",
|
326
|
+
externals
|
327
|
+
},
|
328
|
+
dev: {
|
329
|
+
assetPrefix: "",
|
330
|
+
progressBar: !quiet
|
331
|
+
},
|
332
|
+
source: {
|
333
|
+
alias: {
|
334
|
+
...storybookPaths
|
335
|
+
},
|
336
|
+
entry: {
|
337
|
+
// to avoid `It's not allowed to load an initial chunk on demand. The chunk name "main" is already used by an entrypoint` of
|
338
|
+
main: [...entries ?? [], ...dynamicEntries]
|
339
|
+
},
|
340
|
+
define: {
|
341
|
+
...stringifyProcessEnvs(envs),
|
342
|
+
NODE_ENV: JSON.stringify(process.env.NODE_ENV)
|
343
|
+
}
|
344
|
+
},
|
345
|
+
performance: {
|
346
|
+
chunkSplit: {
|
347
|
+
strategy: "custom",
|
348
|
+
splitChunks: {
|
349
|
+
chunks: "all"
|
350
|
+
}
|
351
|
+
}
|
352
|
+
},
|
353
|
+
tools: {
|
354
|
+
rspack: (config, { addRules, appendPlugins, rspack, mergeConfig }) => {
|
355
|
+
addRules({
|
356
|
+
test: /\.stories\.([tj])sx?$|(stories|story)\.mdx$/,
|
357
|
+
exclude: /node_modules/,
|
358
|
+
enforce: "post",
|
359
|
+
use: [
|
360
|
+
{
|
361
|
+
loader: __require.resolve(
|
362
|
+
"storybook-builder-rsbuild/loaders/export-order-loader"
|
363
|
+
)
|
364
|
+
}
|
365
|
+
]
|
366
|
+
});
|
367
|
+
config.resolve ??= {};
|
368
|
+
config.resolve.symlinks = !isPreservingSymlinks();
|
369
|
+
config.watchOptions = {
|
370
|
+
ignored: /node_modules/
|
371
|
+
};
|
372
|
+
config.output = config.output || {};
|
373
|
+
config.output.publicPath = "";
|
374
|
+
config.ignoreWarnings = [
|
375
|
+
...config.ignoreWarnings || [],
|
376
|
+
/export '\S+' was not found in 'global'/,
|
377
|
+
/export '\S+' was not found in '@storybook\/global'/
|
378
|
+
];
|
379
|
+
config.resolve ??= {};
|
380
|
+
config.resolve.fallback ??= {
|
381
|
+
stream: false,
|
382
|
+
path: __require.resolve("path-browserify"),
|
383
|
+
assert: __require.resolve("browser-assert"),
|
384
|
+
util: __require.resolve("util"),
|
385
|
+
url: __require.resolve("url"),
|
386
|
+
fs: false,
|
387
|
+
constants: __require.resolve("constants-browserify")
|
388
|
+
};
|
389
|
+
config.optimization ??= {};
|
390
|
+
config.optimization.runtimeChunk = true;
|
391
|
+
config.optimization.usedExports = options.build?.test?.disableTreeShaking ? false : isProd;
|
392
|
+
config.optimization.moduleIds = "named";
|
393
|
+
appendPlugins(
|
394
|
+
[
|
395
|
+
new rspack.ProvidePlugin({
|
396
|
+
process: __require.resolve("process/browser.js")
|
397
|
+
}),
|
398
|
+
new CaseSensitivePathsPlugin()
|
399
|
+
].filter(Boolean)
|
400
|
+
);
|
401
|
+
return mergeConfig(config, appliedDocsWebpack);
|
402
|
+
},
|
403
|
+
htmlPlugin: {
|
404
|
+
filename: `iframe.html`,
|
405
|
+
// FIXME: `none` isn't a known option
|
406
|
+
chunksSortMode: "none",
|
407
|
+
alwaysWriteToDisk: true,
|
408
|
+
inject: false,
|
409
|
+
template,
|
410
|
+
templateParameters: {
|
411
|
+
version: packageJson.version,
|
412
|
+
globals: {
|
413
|
+
CONFIG_TYPE: configType,
|
414
|
+
LOGLEVEL: logLevel,
|
415
|
+
FRAMEWORK_OPTIONS: frameworkOptions,
|
416
|
+
CHANNEL_OPTIONS: coreOptions.channelOptions,
|
417
|
+
FEATURES: features,
|
418
|
+
PREVIEW_URL: previewUrl,
|
419
|
+
STORIES: stories.map((specifier) => ({
|
420
|
+
...specifier,
|
421
|
+
importPathMatcher: specifier.importPathMatcher.source
|
422
|
+
})),
|
423
|
+
DOCS_OPTIONS: docsOptions,
|
424
|
+
TAGS_OPTIONS: tagsOptions,
|
425
|
+
...build2?.test?.disableBlocks ? { __STORYBOOK_BLOCKS_EMPTY_MODULE__: {} } : {}
|
426
|
+
},
|
427
|
+
headHtmlSnippet,
|
428
|
+
bodyHtmlSnippet
|
429
|
+
},
|
430
|
+
minify: {
|
431
|
+
collapseWhitespace: true,
|
432
|
+
removeComments: true,
|
433
|
+
removeRedundantAttributes: true,
|
434
|
+
removeScriptTypeAttributes: false,
|
435
|
+
removeStyleLinkTypeAttributes: true,
|
436
|
+
useShortDoctype: true
|
437
|
+
}
|
438
|
+
}
|
439
|
+
}
|
440
|
+
});
|
441
|
+
return merged;
|
442
|
+
};
|
443
|
+
|
444
|
+
// src/index.ts
|
445
|
+
var import_pretty_hrtime = __toESM(require_pretty_hrtime());
|
446
|
+
var printDuration = (startTime) => (0, import_pretty_hrtime.default)(process.hrtime(startTime)).replace(" ms", " milliseconds").replace(" s", " seconds").replace(" m", " minutes");
|
447
|
+
var getAbsolutePath2 = (input) => dirname(__require.resolve(join(input, "package.json")));
|
448
|
+
var executor = {
|
449
|
+
get: async (options) => {
|
450
|
+
const rsbuildInstance = await options.presets.apply("rsbuildInstance") || rsbuildReal;
|
451
|
+
return rsbuildInstance;
|
452
|
+
}
|
453
|
+
};
|
454
|
+
var rsbuild = async (_, options) => {
|
455
|
+
const defaultConfig = await iframe_rsbuild_config_default(options);
|
456
|
+
const { presets } = options;
|
457
|
+
const finalDefaultConfig = await presets.apply(
|
458
|
+
"rsbuildFinal",
|
459
|
+
defaultConfig,
|
460
|
+
options
|
461
|
+
);
|
462
|
+
return finalDefaultConfig;
|
463
|
+
};
|
464
|
+
var getConfig = async (options) => {
|
465
|
+
const { presets } = options;
|
466
|
+
const typescriptOptions = await presets.apply("typescript", {}, options);
|
467
|
+
const frameworkOptions = await presets.apply("frameworkOptions");
|
468
|
+
return rsbuild({}, {
|
469
|
+
...options,
|
470
|
+
typescriptOptions,
|
471
|
+
frameworkOptions
|
472
|
+
});
|
473
|
+
};
|
474
|
+
var server;
|
475
|
+
async function bail() {
|
476
|
+
return server?.close();
|
477
|
+
}
|
478
|
+
var start = async ({
|
479
|
+
startTime,
|
480
|
+
options,
|
481
|
+
router,
|
482
|
+
server: storybookServer,
|
483
|
+
channel
|
484
|
+
}) => {
|
485
|
+
const { createRsbuild } = await executor.get(options);
|
486
|
+
const config = await getConfig(options);
|
487
|
+
const rsbuildBuild = await createRsbuild({
|
488
|
+
cwd: process.cwd(),
|
489
|
+
rsbuildConfig: {
|
490
|
+
...config,
|
491
|
+
server: {
|
492
|
+
...config.server,
|
493
|
+
port: options.port,
|
494
|
+
host: "localhost",
|
495
|
+
htmlFallback: false,
|
496
|
+
strictPort: true,
|
497
|
+
printUrls: false
|
498
|
+
},
|
499
|
+
dev: {
|
500
|
+
client: {}
|
501
|
+
}
|
502
|
+
}
|
503
|
+
});
|
504
|
+
const rsbuildServer = await rsbuildBuild.createDevServer();
|
505
|
+
server = rsbuildServer;
|
506
|
+
if (!rsbuildBuild) {
|
507
|
+
throw new WebpackInvocationError({
|
508
|
+
// eslint-disable-next-line local-rules/no-uncategorized-errors
|
509
|
+
error: new Error(`Missing Rsbuild build instance at runtime!`)
|
510
|
+
});
|
511
|
+
}
|
512
|
+
const previewResolvedDir = getAbsolutePath2("@storybook/preview");
|
513
|
+
const previewDirOrigin = join(previewResolvedDir, "dist");
|
514
|
+
router.use(
|
515
|
+
`/sb-preview`,
|
516
|
+
express.static(previewDirOrigin, { immutable: true, maxAge: "5m" })
|
517
|
+
);
|
518
|
+
router.use(rsbuildServer.middlewares);
|
519
|
+
storybookServer.on("upgrade", rsbuildServer.onHTTPUpgrade);
|
520
|
+
return {
|
521
|
+
bail,
|
522
|
+
stats: {
|
523
|
+
toJson: () => {
|
524
|
+
throw new NoStatsForViteDevError();
|
525
|
+
}
|
526
|
+
},
|
527
|
+
totalTime: process.hrtime(startTime)
|
528
|
+
};
|
529
|
+
};
|
530
|
+
var build = async ({ options }) => {
|
531
|
+
const { createRsbuild } = await executor.get(options);
|
532
|
+
const config = await getConfig(options);
|
533
|
+
const rsbuildBuild = await createRsbuild({
|
534
|
+
cwd: process.cwd(),
|
535
|
+
rsbuildConfig: config
|
536
|
+
});
|
537
|
+
const previewResolvedDir = getAbsolutePath2("@storybook/preview");
|
538
|
+
const previewDirOrigin = join(previewResolvedDir, "dist");
|
539
|
+
const previewDirTarget = join(options.outputDir || "", `sb-preview`);
|
540
|
+
const previewFiles = fs2.copy(previewDirOrigin, previewDirTarget, {
|
541
|
+
filter: (src) => {
|
542
|
+
const { ext } = parse(src);
|
543
|
+
if (ext) {
|
544
|
+
return ext === ".js";
|
545
|
+
}
|
546
|
+
return true;
|
547
|
+
}
|
548
|
+
});
|
549
|
+
await Promise.all([rsbuildBuild.build(), previewFiles]);
|
550
|
+
};
|
551
|
+
var corePresets = [join(__dirname, "./preview-preset.js")];
|
552
|
+
var previewMainTemplate = () => __require.resolve("storybook-builder-rsbuild/templates/preview.ejs");
|
553
|
+
|
554
|
+
export { bail, build, corePresets, executor, getConfig, getVirtualModules, importPipeline, previewMainTemplate, printDuration, rsbuild, start, toImportFn, toImportFnPart };
|
@@ -0,0 +1,72 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __create = Object.create;
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __export = (target, all) => {
|
9
|
+
for (var name in all)
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
+
};
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
+
for (let key of __getOwnPropNames(from))
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
+
}
|
18
|
+
return to;
|
19
|
+
};
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
+
mod
|
27
|
+
));
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
+
|
30
|
+
// src/loaders/export-order-loader.ts
|
31
|
+
var export_order_loader_exports = {};
|
32
|
+
__export(export_order_loader_exports, {
|
33
|
+
default: () => loader
|
34
|
+
});
|
35
|
+
module.exports = __toCommonJS(export_order_loader_exports);
|
36
|
+
var import_node_assert = __toESM(require("assert"));
|
37
|
+
var import_cjs_module_lexer = require("cjs-module-lexer");
|
38
|
+
var import_es_module_lexer = require("es-module-lexer");
|
39
|
+
var import_magic_string = __toESM(require("magic-string"));
|
40
|
+
async function loader(source, map, meta) {
|
41
|
+
const callback = this.async();
|
42
|
+
try {
|
43
|
+
const magicString = new import_magic_string.default(source);
|
44
|
+
try {
|
45
|
+
const parseResult = await (0, import_es_module_lexer.parse)(source);
|
46
|
+
const namedExportsOrder = (parseResult[1] || []).map((e) => source.substring(e.s, e.e)).filter((e) => e !== "default");
|
47
|
+
(0, import_node_assert.default)(
|
48
|
+
namedExportsOrder.length > 0,
|
49
|
+
"No named exports found. Very likely that this is not a ES module."
|
50
|
+
);
|
51
|
+
magicString.append(
|
52
|
+
`;export const __namedExportsOrder = ${JSON.stringify(namedExportsOrder)};`
|
53
|
+
);
|
54
|
+
} catch {
|
55
|
+
await (0, import_cjs_module_lexer.init)();
|
56
|
+
const namedExportsOrder = ((0, import_cjs_module_lexer.parse)(source).exports || []).filter(
|
57
|
+
(e) => e !== "default" && e !== "__esModule"
|
58
|
+
);
|
59
|
+
(0, import_node_assert.default)(
|
60
|
+
namedExportsOrder.length > 0,
|
61
|
+
"No named exports found. Very likely that this is not a CJS module."
|
62
|
+
);
|
63
|
+
magicString.append(
|
64
|
+
`;module.exports.__namedExportsOrder = ${JSON.stringify(namedExportsOrder)};`
|
65
|
+
);
|
66
|
+
}
|
67
|
+
const generatedMap = magicString.generateMap({ hires: true });
|
68
|
+
return callback(null, magicString.toString(), generatedMap, meta);
|
69
|
+
} catch (err) {
|
70
|
+
return callback(null, source, map, meta);
|
71
|
+
}
|
72
|
+
}
|
@@ -0,0 +1,41 @@
|
|
1
|
+
import '../chunk-TTFRSOOU.mjs';
|
2
|
+
import assert from 'assert';
|
3
|
+
import { init, parse as parse$1 } from 'cjs-module-lexer';
|
4
|
+
import { parse } from 'es-module-lexer';
|
5
|
+
import MagicString from 'magic-string';
|
6
|
+
|
7
|
+
async function loader(source, map, meta) {
|
8
|
+
const callback = this.async();
|
9
|
+
try {
|
10
|
+
const magicString = new MagicString(source);
|
11
|
+
try {
|
12
|
+
const parseResult = await parse(source);
|
13
|
+
const namedExportsOrder = (parseResult[1] || []).map((e) => source.substring(e.s, e.e)).filter((e) => e !== "default");
|
14
|
+
assert(
|
15
|
+
namedExportsOrder.length > 0,
|
16
|
+
"No named exports found. Very likely that this is not a ES module."
|
17
|
+
);
|
18
|
+
magicString.append(
|
19
|
+
`;export const __namedExportsOrder = ${JSON.stringify(namedExportsOrder)};`
|
20
|
+
);
|
21
|
+
} catch {
|
22
|
+
await init();
|
23
|
+
const namedExportsOrder = (parse$1(source).exports || []).filter(
|
24
|
+
(e) => e !== "default" && e !== "__esModule"
|
25
|
+
);
|
26
|
+
assert(
|
27
|
+
namedExportsOrder.length > 0,
|
28
|
+
"No named exports found. Very likely that this is not a CJS module."
|
29
|
+
);
|
30
|
+
magicString.append(
|
31
|
+
`;module.exports.__namedExportsOrder = ${JSON.stringify(namedExportsOrder)};`
|
32
|
+
);
|
33
|
+
}
|
34
|
+
const generatedMap = magicString.generateMap({ hires: true });
|
35
|
+
return callback(null, magicString.toString(), generatedMap, meta);
|
36
|
+
} catch (err) {
|
37
|
+
return callback(null, source, map, meta);
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
export { loader as default };
|