storybook-builder-rsbuild 0.0.4 → 0.0.6
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.d.ts +18 -7
- package/dist/index.js +27 -9
- package/dist/index.mjs +28 -10
- package/dist/loaders/export-order-loader.js +10 -2
- package/dist/loaders/export-order-loader.mjs +10 -2
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import * as rsbuildReal from '@rsbuild/core';
|
2
2
|
import { RsbuildConfig } from '@rsbuild/core';
|
3
|
-
import { TypescriptOptions as TypescriptOptions$1, Builder, Options, NormalizedStoriesSpecifier } from '@storybook/types';
|
4
|
-
import
|
3
|
+
import { TypescriptOptions as TypescriptOptions$1, Builder, Options, BuilderResult as BuilderResult$1, NormalizedStoriesSpecifier } from '@storybook/types';
|
4
|
+
import { PluginTypeCheckerOptions } from '@rsbuild/plugin-type-check';
|
5
5
|
|
6
6
|
type RsbuildStats = {
|
7
7
|
toJson: () => any;
|
@@ -11,9 +11,9 @@ type RsbuildStats = {
|
|
11
11
|
*/
|
12
12
|
interface TypescriptOptions extends TypescriptOptions$1 {
|
13
13
|
/**
|
14
|
-
* Configures `fork-ts-checker-webpack-plugin`
|
14
|
+
* Configures `@rsbuild/plugin-type-check`, using `fork-ts-checker-webpack-plugin` under the hood.
|
15
15
|
*/
|
16
|
-
checkOptions?:
|
16
|
+
checkOptions?: PluginTypeCheckerOptions;
|
17
17
|
}
|
18
18
|
type RsbuildBuilder = Builder<RsbuildConfig, RsbuildStats>;
|
19
19
|
type RsbuildFinal = (config: RsbuildConfig, options: Options) => RsbuildConfig | Promise<RsbuildConfig>;
|
@@ -26,6 +26,13 @@ type BuilderOptions = {
|
|
26
26
|
*/
|
27
27
|
rsbuildConfigPath?: string;
|
28
28
|
};
|
29
|
+
interface BuilderResult extends BuilderResult$1 {
|
30
|
+
stats?: Stats;
|
31
|
+
}
|
32
|
+
|
33
|
+
type RsbuildBuilderOptions = Options & {
|
34
|
+
typescriptOptions: TypescriptOptions;
|
35
|
+
};
|
29
36
|
|
30
37
|
declare const getVirtualModules: (options: Options) => Promise<{
|
31
38
|
virtualModules: Record<string, string>;
|
@@ -38,17 +45,21 @@ declare function toImportFn(stories: NormalizedStoriesSpecifier[], relativeOffse
|
|
38
45
|
type ModuleExports = Record<string, any>;
|
39
46
|
declare function importPipeline(): (importFn: () => Promise<ModuleExports>) => Promise<ModuleExports>;
|
40
47
|
|
48
|
+
type StatsOrMultiStats = Parameters<rsbuildReal.OnAfterBuildFn>[0]['stats'];
|
49
|
+
type Stats = NonNullable<Exclude<StatsOrMultiStats, {
|
50
|
+
stats: unknown[];
|
51
|
+
}>>;
|
41
52
|
declare const printDuration: (startTime: [number, number]) => string;
|
42
53
|
type BuilderStartOptions = Parameters<RsbuildBuilder['start']>['0'];
|
43
54
|
declare const executor: {
|
44
55
|
get: (options: Options) => Promise<typeof rsbuildReal>;
|
45
56
|
};
|
46
|
-
declare const rsbuild: (_: unknown, options:
|
57
|
+
declare const rsbuild: (_: unknown, options: RsbuildBuilderOptions) => Promise<rsbuildReal.RsbuildConfig>;
|
47
58
|
declare const getConfig: RsbuildBuilder['getConfig'];
|
48
59
|
declare function bail(): Promise<void>;
|
49
60
|
declare const start: RsbuildBuilder['start'];
|
50
|
-
declare const build: ({ options }: BuilderStartOptions) => Promise<
|
61
|
+
declare const build: ({ options, }: BuilderStartOptions) => Promise<Stats>;
|
51
62
|
declare const corePresets: string[];
|
52
63
|
declare const previewMainTemplate: () => string;
|
53
64
|
|
54
|
-
export { BuilderOptions, RsbuildBuilder, RsbuildFinal, StorybookConfigRsbuild, TypescriptOptions, bail, build, corePresets, executor, getConfig, getVirtualModules, importPipeline, previewMainTemplate, printDuration, rsbuild, start, toImportFn, toImportFnPart };
|
65
|
+
export { BuilderOptions, BuilderResult, RsbuildBuilder, RsbuildFinal, Stats, StorybookConfigRsbuild, TypescriptOptions, bail, build, corePresets, executor, getConfig, getVirtualModules, importPipeline, previewMainTemplate, printDuration, rsbuild, start, toImportFn, toImportFnPart };
|
package/dist/index.js
CHANGED
@@ -162,7 +162,7 @@ var getVirtualModules = async (options) => {
|
|
162
162
|
configDir: options.configDir,
|
163
163
|
workingDir
|
164
164
|
});
|
165
|
-
const realPathRelativeToCwd = import_path.default.relative(workingDir, cwd);
|
165
|
+
const realPathRelativeToCwd = import_path.default.relative(workingDir, cwd).split(import_path.default.sep).join(import_path.default.posix.sep);
|
166
166
|
const previewAnnotations = [
|
167
167
|
...(await options.presets.apply(
|
168
168
|
"previewAnnotations",
|
@@ -272,7 +272,7 @@ function importPipeline() {
|
|
272
272
|
// src/preview/iframe-rsbuild.config.ts
|
273
273
|
var import_core = require("@rsbuild/core");
|
274
274
|
var import_preset = require("@storybook/addon-docs/dist/preset");
|
275
|
-
var
|
275
|
+
var import_plugin_type_check = require("@rsbuild/plugin-type-check");
|
276
276
|
var getAbsolutePath = (input) => (0, import_path3.dirname)(require.resolve((0, import_path3.join)(input, "package.json")));
|
277
277
|
var maybeGetAbsolutePath = (input) => {
|
278
278
|
try {
|
@@ -394,6 +394,9 @@ var iframe_rsbuild_config_default = async (options) => {
|
|
394
394
|
progressBar: !quiet
|
395
395
|
},
|
396
396
|
source: {
|
397
|
+
// TODO: Rspack doesn't support virtual modules yet, use cache dir instead
|
398
|
+
// we needed to explicitly set the module in `node_modules` to be compiled
|
399
|
+
include: [/[\\/]node_modules[\\/].*[\\/]storybook-config-entry\.js/],
|
397
400
|
alias: {
|
398
401
|
...storybookPaths
|
399
402
|
},
|
@@ -414,6 +417,9 @@ var iframe_rsbuild_config_default = async (options) => {
|
|
414
417
|
}
|
415
418
|
}
|
416
419
|
},
|
420
|
+
plugins: [shouldCheckTs ? (0, import_plugin_type_check.pluginTypeCheck)(tsCheckOptions) : null].filter(
|
421
|
+
Boolean
|
422
|
+
),
|
417
423
|
tools: {
|
418
424
|
rspack: (config, { addRules, appendPlugins, rspack, mergeConfig }) => {
|
419
425
|
addRules({
|
@@ -457,8 +463,7 @@ var iframe_rsbuild_config_default = async (options) => {
|
|
457
463
|
new rspack.ProvidePlugin({
|
458
464
|
process: require.resolve("process/browser.js")
|
459
465
|
}),
|
460
|
-
new import_case_sensitive_paths_webpack_plugin.default()
|
461
|
-
shouldCheckTs ? new import_fork_ts_checker_webpack_plugin.default(tsCheckOptions) : null
|
466
|
+
new import_case_sensitive_paths_webpack_plugin.default()
|
462
467
|
].filter(Boolean)
|
463
468
|
);
|
464
469
|
return mergeConfig(config, appliedDocsWebpack);
|
@@ -565,6 +570,14 @@ var start = async ({
|
|
565
570
|
}
|
566
571
|
});
|
567
572
|
const rsbuildServer = await rsbuildBuild.createDevServer();
|
573
|
+
const waitFirstCompileDone = new Promise((resolve3) => {
|
574
|
+
rsbuildBuild.onDevCompileDone(({ stats: stats2, isFirstCompile }) => {
|
575
|
+
if (!isFirstCompile) {
|
576
|
+
return;
|
577
|
+
}
|
578
|
+
resolve3(stats2);
|
579
|
+
});
|
580
|
+
});
|
568
581
|
server = rsbuildServer;
|
569
582
|
if (!rsbuildBuild) {
|
570
583
|
throw new import_server_errors.WebpackInvocationError({
|
@@ -580,13 +593,10 @@ var start = async ({
|
|
580
593
|
);
|
581
594
|
router.use(rsbuildServer.middlewares);
|
582
595
|
storybookServer.on("upgrade", rsbuildServer.onHTTPUpgrade);
|
596
|
+
const stats = await waitFirstCompileDone;
|
583
597
|
return {
|
584
598
|
bail,
|
585
|
-
stats
|
586
|
-
toJson: () => {
|
587
|
-
throw new import_server_errors.NoStatsForViteDevError();
|
588
|
-
}
|
589
|
-
},
|
599
|
+
stats,
|
590
600
|
totalTime: process.hrtime(startTime)
|
591
601
|
};
|
592
602
|
};
|
@@ -600,6 +610,10 @@ var build = async ({ options }) => {
|
|
600
610
|
const previewResolvedDir = getAbsolutePath2("@storybook/preview");
|
601
611
|
const previewDirOrigin = (0, import_path4.join)(previewResolvedDir, "dist");
|
602
612
|
const previewDirTarget = (0, import_path4.join)(options.outputDir || "", `sb-preview`);
|
613
|
+
let stats;
|
614
|
+
rsbuildBuild.onAfterBuild((params) => {
|
615
|
+
stats = params.stats;
|
616
|
+
});
|
603
617
|
const previewFiles = import_fs_extra.default.copy(previewDirOrigin, previewDirTarget, {
|
604
618
|
filter: (src) => {
|
605
619
|
const { ext } = (0, import_path4.parse)(src);
|
@@ -609,7 +623,11 @@ var build = async ({ options }) => {
|
|
609
623
|
return true;
|
610
624
|
}
|
611
625
|
});
|
626
|
+
rsbuildBuild.onAfterBuild((params) => {
|
627
|
+
stats = params.stats;
|
628
|
+
});
|
612
629
|
await Promise.all([rsbuildBuild.build(), previewFiles]);
|
630
|
+
return stats;
|
613
631
|
};
|
614
632
|
var corePresets = [(0, import_path4.join)(__dirname, "./preview-preset.js")];
|
615
633
|
var previewMainTemplate = () => require.resolve("storybook-builder-rsbuild/templates/preview.ejs");
|
package/dist/index.mjs
CHANGED
@@ -4,7 +4,7 @@ import { loadConfig, mergeRsbuildConfig } from '@rsbuild/core';
|
|
4
4
|
import path, { join, resolve, parse, dirname } from 'path';
|
5
5
|
import express from 'express';
|
6
6
|
import fs2 from 'fs-extra';
|
7
|
-
import { WebpackInvocationError
|
7
|
+
import { WebpackInvocationError } from '@storybook/core-events/server-errors';
|
8
8
|
import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin';
|
9
9
|
import { globalsNameReferenceMap } from '@storybook/preview/globals';
|
10
10
|
import { normalizeStories, loadPreviewOrConfigFile, handlebars, readTemplate, getBuilderOptions, stringifyProcessEnvs, isPreservingSymlinks } from '@storybook/core-common';
|
@@ -12,7 +12,7 @@ import { dedent } from 'ts-dedent';
|
|
12
12
|
import fs from 'fs';
|
13
13
|
import { webpackIncludeRegexp } from '@storybook/core-webpack';
|
14
14
|
import { webpack } from '@storybook/addon-docs/dist/preset';
|
15
|
-
import
|
15
|
+
import { pluginTypeCheck } from '@rsbuild/plugin-type-check';
|
16
16
|
|
17
17
|
// ../../node_modules/.pnpm/pretty-hrtime@1.0.3/node_modules/pretty-hrtime/index.js
|
18
18
|
var require_pretty_hrtime = __commonJS({
|
@@ -104,7 +104,7 @@ var getVirtualModules = async (options) => {
|
|
104
104
|
configDir: options.configDir,
|
105
105
|
workingDir
|
106
106
|
});
|
107
|
-
const realPathRelativeToCwd = path.relative(workingDir, cwd);
|
107
|
+
const realPathRelativeToCwd = path.relative(workingDir, cwd).split(path.sep).join(path.posix.sep);
|
108
108
|
const previewAnnotations = [
|
109
109
|
...(await options.presets.apply(
|
110
110
|
"previewAnnotations",
|
@@ -333,6 +333,9 @@ var iframe_rsbuild_config_default = async (options) => {
|
|
333
333
|
progressBar: !quiet
|
334
334
|
},
|
335
335
|
source: {
|
336
|
+
// TODO: Rspack doesn't support virtual modules yet, use cache dir instead
|
337
|
+
// we needed to explicitly set the module in `node_modules` to be compiled
|
338
|
+
include: [/[\\/]node_modules[\\/].*[\\/]storybook-config-entry\.js/],
|
336
339
|
alias: {
|
337
340
|
...storybookPaths
|
338
341
|
},
|
@@ -353,6 +356,9 @@ var iframe_rsbuild_config_default = async (options) => {
|
|
353
356
|
}
|
354
357
|
}
|
355
358
|
},
|
359
|
+
plugins: [shouldCheckTs ? pluginTypeCheck(tsCheckOptions) : null].filter(
|
360
|
+
Boolean
|
361
|
+
),
|
356
362
|
tools: {
|
357
363
|
rspack: (config, { addRules, appendPlugins, rspack, mergeConfig }) => {
|
358
364
|
addRules({
|
@@ -398,8 +404,7 @@ var iframe_rsbuild_config_default = async (options) => {
|
|
398
404
|
new rspack.ProvidePlugin({
|
399
405
|
process: __require.resolve("process/browser.js")
|
400
406
|
}),
|
401
|
-
new CaseSensitivePathsPlugin()
|
402
|
-
shouldCheckTs ? new ForkTsCheckerWebpackPlugin(tsCheckOptions) : null
|
407
|
+
new CaseSensitivePathsPlugin()
|
403
408
|
].filter(Boolean)
|
404
409
|
);
|
405
410
|
return mergeConfig(config, appliedDocsWebpack);
|
@@ -506,6 +511,14 @@ var start = async ({
|
|
506
511
|
}
|
507
512
|
});
|
508
513
|
const rsbuildServer = await rsbuildBuild.createDevServer();
|
514
|
+
const waitFirstCompileDone = new Promise((resolve3) => {
|
515
|
+
rsbuildBuild.onDevCompileDone(({ stats: stats2, isFirstCompile }) => {
|
516
|
+
if (!isFirstCompile) {
|
517
|
+
return;
|
518
|
+
}
|
519
|
+
resolve3(stats2);
|
520
|
+
});
|
521
|
+
});
|
509
522
|
server = rsbuildServer;
|
510
523
|
if (!rsbuildBuild) {
|
511
524
|
throw new WebpackInvocationError({
|
@@ -521,13 +534,10 @@ var start = async ({
|
|
521
534
|
);
|
522
535
|
router.use(rsbuildServer.middlewares);
|
523
536
|
storybookServer.on("upgrade", rsbuildServer.onHTTPUpgrade);
|
537
|
+
const stats = await waitFirstCompileDone;
|
524
538
|
return {
|
525
539
|
bail,
|
526
|
-
stats
|
527
|
-
toJson: () => {
|
528
|
-
throw new NoStatsForViteDevError();
|
529
|
-
}
|
530
|
-
},
|
540
|
+
stats,
|
531
541
|
totalTime: process.hrtime(startTime)
|
532
542
|
};
|
533
543
|
};
|
@@ -541,6 +551,10 @@ var build = async ({ options }) => {
|
|
541
551
|
const previewResolvedDir = getAbsolutePath2("@storybook/preview");
|
542
552
|
const previewDirOrigin = join(previewResolvedDir, "dist");
|
543
553
|
const previewDirTarget = join(options.outputDir || "", `sb-preview`);
|
554
|
+
let stats;
|
555
|
+
rsbuildBuild.onAfterBuild((params) => {
|
556
|
+
stats = params.stats;
|
557
|
+
});
|
544
558
|
const previewFiles = fs2.copy(previewDirOrigin, previewDirTarget, {
|
545
559
|
filter: (src) => {
|
546
560
|
const { ext } = parse(src);
|
@@ -550,7 +564,11 @@ var build = async ({ options }) => {
|
|
550
564
|
return true;
|
551
565
|
}
|
552
566
|
});
|
567
|
+
rsbuildBuild.onAfterBuild((params) => {
|
568
|
+
stats = params.stats;
|
569
|
+
});
|
553
570
|
await Promise.all([rsbuildBuild.build(), previewFiles]);
|
571
|
+
return stats;
|
554
572
|
};
|
555
573
|
var corePresets = [join(__dirname, "./preview-preset.js")];
|
556
574
|
var previewMainTemplate = () => __require.resolve("storybook-builder-rsbuild/templates/preview.ejs");
|
@@ -64,8 +64,16 @@ async function loader(source, map, meta) {
|
|
64
64
|
`;module.exports.__namedExportsOrder = ${JSON.stringify(namedExportsOrder)};`
|
65
65
|
);
|
66
66
|
}
|
67
|
-
|
68
|
-
|
67
|
+
return callback(
|
68
|
+
null,
|
69
|
+
magicString.toString(),
|
70
|
+
map ?? magicString.generateMap({
|
71
|
+
hires: true,
|
72
|
+
includeContent: true,
|
73
|
+
source: this.resourcePath
|
74
|
+
}),
|
75
|
+
meta
|
76
|
+
);
|
69
77
|
} catch (err) {
|
70
78
|
return callback(null, source, map, meta);
|
71
79
|
}
|
@@ -31,8 +31,16 @@ async function loader(source, map, meta) {
|
|
31
31
|
`;module.exports.__namedExportsOrder = ${JSON.stringify(namedExportsOrder)};`
|
32
32
|
);
|
33
33
|
}
|
34
|
-
|
35
|
-
|
34
|
+
return callback(
|
35
|
+
null,
|
36
|
+
magicString.toString(),
|
37
|
+
map ?? magicString.generateMap({
|
38
|
+
hires: true,
|
39
|
+
includeContent: true,
|
40
|
+
source: this.resourcePath
|
41
|
+
}),
|
42
|
+
meta
|
43
|
+
);
|
36
44
|
} catch (err) {
|
37
45
|
return callback(null, source, map, meta);
|
38
46
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "storybook-builder-rsbuild",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.6",
|
4
4
|
"description": "Rsbuild builder for Storybook",
|
5
5
|
"keywords": [
|
6
6
|
"storybook",
|
@@ -56,6 +56,7 @@
|
|
56
56
|
"!src/**/*"
|
57
57
|
],
|
58
58
|
"dependencies": {
|
59
|
+
"@rsbuild/plugin-type-check": "0.7.9",
|
59
60
|
"@storybook/addon-docs": "^8.0.10",
|
60
61
|
"@storybook/channels": "^8.0.10",
|
61
62
|
"@storybook/client-logger": "^8.0.10",
|
@@ -74,7 +75,6 @@
|
|
74
75
|
"css-loader": "^6.7.1",
|
75
76
|
"es-module-lexer": "^1.5.0",
|
76
77
|
"express": "^4.17.3",
|
77
|
-
"fork-ts-checker-webpack-plugin": "^8.0.0",
|
78
78
|
"fs-extra": "^11.1.0",
|
79
79
|
"magic-string": "^0.30.5",
|
80
80
|
"path-browserify": "^1.0.1",
|
@@ -86,7 +86,7 @@
|
|
86
86
|
"util-deprecate": "^1.0.2"
|
87
87
|
},
|
88
88
|
"devDependencies": {
|
89
|
-
"@rsbuild/core": "0.
|
89
|
+
"@rsbuild/core": "0.7.9",
|
90
90
|
"@types/express": "^4.17.21",
|
91
91
|
"@types/fs-extra": "^11.0.4",
|
92
92
|
"@types/node": "^18.0.0",
|
@@ -97,7 +97,7 @@
|
|
97
97
|
"typescript": "^5.3.2"
|
98
98
|
},
|
99
99
|
"peerDependencies": {
|
100
|
-
"@rsbuild/core": ">= 0.
|
100
|
+
"@rsbuild/core": ">= 0.7.0"
|
101
101
|
},
|
102
102
|
"peerDependenciesMeta": {
|
103
103
|
"typescript": {
|