storybook-builder-rsbuild 0.0.6-beta.1 → 0.0.6-beta.2
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 +2 -1
- package/dist/index.js +50 -8
- package/dist/index.mjs +40 -4
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import * as _storybook_core_webpack from '@storybook/core-webpack';
|
1
2
|
import * as rsbuildReal from '@rsbuild/core';
|
2
3
|
import { RsbuildConfig } from '@rsbuild/core';
|
3
4
|
import { TypescriptOptions as TypescriptOptions$1, Builder, Options, BuilderResult as BuilderResult$1, NormalizedStoriesSpecifier } from 'storybook/internal/types';
|
@@ -54,7 +55,7 @@ type BuilderStartOptions = Parameters<RsbuildBuilder['start']>['0'];
|
|
54
55
|
declare const executor: {
|
55
56
|
get: (options: Options) => Promise<typeof rsbuildReal>;
|
56
57
|
};
|
57
|
-
declare const rsbuild: (_: unknown, options: RsbuildBuilderOptions) => Promise<
|
58
|
+
declare const rsbuild: (_: unknown, options: RsbuildBuilderOptions) => Promise<_storybook_core_webpack.WebpackConfiguration>;
|
58
59
|
declare const getConfig: RsbuildBuilder['getConfig'];
|
59
60
|
declare function bail(): Promise<void>;
|
60
61
|
declare const start: RsbuildBuilder['start'];
|
package/dist/index.js
CHANGED
@@ -121,7 +121,7 @@ __export(src_exports, {
|
|
121
121
|
});
|
122
122
|
module.exports = __toCommonJS(src_exports);
|
123
123
|
var rsbuildReal = __toESM(require("@rsbuild/core"));
|
124
|
-
var
|
124
|
+
var import_path5 = require("path");
|
125
125
|
var import_express = __toESM(require("express"));
|
126
126
|
var import_fs_extra = __toESM(require("fs-extra"));
|
127
127
|
var import_server_errors = require("storybook/internal/server-errors");
|
@@ -515,7 +515,47 @@ var iframe_rsbuild_config_default = async (options) => {
|
|
515
515
|
|
516
516
|
// src/index.ts
|
517
517
|
var import_core_path = require("storybook/core-path");
|
518
|
+
|
519
|
+
// src/react-shims.ts
|
520
|
+
var import_path4 = require("path");
|
521
|
+
var import_promises = require("fs/promises");
|
522
|
+
var getIsReactVersion18or19 = async (options) => {
|
523
|
+
const { legacyRootApi } = await options.presets.apply(
|
524
|
+
"frameworkOptions"
|
525
|
+
) || {};
|
526
|
+
if (legacyRootApi) {
|
527
|
+
return false;
|
528
|
+
}
|
529
|
+
const resolvedReact = await options.presets.apply(
|
530
|
+
"resolvedReact",
|
531
|
+
{}
|
532
|
+
);
|
533
|
+
const reactDom = resolvedReact.reactDom || (0, import_path4.dirname)(require.resolve("react-dom/package.json"));
|
534
|
+
if (!(0, import_path4.isAbsolute)(reactDom)) {
|
535
|
+
return false;
|
536
|
+
}
|
537
|
+
const { version } = JSON.parse(
|
538
|
+
await (0, import_promises.readFile)((0, import_path4.join)(reactDom, "package.json"), "utf-8")
|
539
|
+
);
|
540
|
+
return version.startsWith("18") || version.startsWith("19") || version.startsWith("0.0.0");
|
541
|
+
};
|
542
|
+
var applyReactShims = async (config, options) => {
|
543
|
+
const isReactVersion18 = await getIsReactVersion18or19(options);
|
544
|
+
if (isReactVersion18) {
|
545
|
+
return config;
|
546
|
+
}
|
547
|
+
return {
|
548
|
+
source: {
|
549
|
+
alias: {
|
550
|
+
"@storybook/react-dom-shim": "@storybook/react-dom-shim/dist/react-16"
|
551
|
+
}
|
552
|
+
}
|
553
|
+
};
|
554
|
+
};
|
555
|
+
|
556
|
+
// src/index.ts
|
518
557
|
var import_pretty_hrtime = __toESM(require_pretty_hrtime());
|
558
|
+
var import_core_webpack2 = require("@storybook/core-webpack");
|
519
559
|
var printDuration = (startTime) => (0, import_pretty_hrtime.default)(process.hrtime(startTime)).replace(" ms", " milliseconds").replace(" s", " seconds").replace(" m", " minutes");
|
520
560
|
var executor = {
|
521
561
|
get: async (options) => {
|
@@ -524,14 +564,16 @@ var executor = {
|
|
524
564
|
}
|
525
565
|
};
|
526
566
|
var rsbuild = async (_, options) => {
|
527
|
-
const defaultConfig = await iframe_rsbuild_config_default(options);
|
528
567
|
const { presets } = options;
|
568
|
+
let defaultConfig = await iframe_rsbuild_config_default(options);
|
569
|
+
const shimsConfig = await applyReactShims(defaultConfig, options);
|
570
|
+
defaultConfig = (0, import_core_webpack2.mergeConfigs)(defaultConfig, shimsConfig);
|
529
571
|
const finalDefaultConfig = await presets.apply(
|
530
572
|
"rsbuildFinal",
|
531
573
|
defaultConfig,
|
532
574
|
options
|
533
575
|
);
|
534
|
-
return finalDefaultConfig;
|
576
|
+
return (0, import_core_webpack2.mergeConfigs)(finalDefaultConfig, shimsConfig);
|
535
577
|
};
|
536
578
|
var getConfig = async (options) => {
|
537
579
|
const { presets } = options;
|
@@ -589,7 +631,7 @@ var start = async ({
|
|
589
631
|
error: new Error(`Missing Rsbuild build instance at runtime!`)
|
590
632
|
});
|
591
633
|
}
|
592
|
-
const previewResolvedDir = (0,
|
634
|
+
const previewResolvedDir = (0, import_path5.join)(import_core_path.corePath, "dist/preview");
|
593
635
|
const previewDirOrigin = previewResolvedDir;
|
594
636
|
router.use(
|
595
637
|
`/sb-preview`,
|
@@ -611,16 +653,16 @@ var build = async ({ options }) => {
|
|
611
653
|
cwd: process.cwd(),
|
612
654
|
rsbuildConfig: config
|
613
655
|
});
|
614
|
-
const previewResolvedDir = (0,
|
656
|
+
const previewResolvedDir = (0, import_path5.join)(import_core_path.corePath, "dist/preview");
|
615
657
|
const previewDirOrigin = previewResolvedDir;
|
616
|
-
const previewDirTarget = (0,
|
658
|
+
const previewDirTarget = (0, import_path5.join)(options.outputDir || "", `sb-preview`);
|
617
659
|
let stats;
|
618
660
|
rsbuildBuild.onAfterBuild((params) => {
|
619
661
|
stats = params.stats;
|
620
662
|
});
|
621
663
|
const previewFiles = import_fs_extra.default.copy(previewDirOrigin, previewDirTarget, {
|
622
664
|
filter: (src) => {
|
623
|
-
const { ext } = (0,
|
665
|
+
const { ext } = (0, import_path5.parse)(src);
|
624
666
|
if (ext) {
|
625
667
|
return ext === ".js";
|
626
668
|
}
|
@@ -633,7 +675,7 @@ var build = async ({ options }) => {
|
|
633
675
|
await Promise.all([rsbuildBuild.build(), previewFiles]);
|
634
676
|
return stats;
|
635
677
|
};
|
636
|
-
var corePresets = [(0,
|
678
|
+
var corePresets = [(0, import_path5.join)(__dirname, "./preview-preset.js")];
|
637
679
|
var previewMainTemplate = () => require.resolve("storybook-builder-rsbuild/templates/preview.ejs");
|
638
680
|
// Annotate the CommonJS export names for ESM import in node:
|
639
681
|
0 && (module.exports = {
|
package/dist/index.mjs
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { __commonJS, __toESM, __require } from './chunk-TTFRSOOU.mjs';
|
2
2
|
import * as rsbuildReal from '@rsbuild/core';
|
3
3
|
import { loadConfig, mergeRsbuildConfig } from '@rsbuild/core';
|
4
|
-
import path, { join, resolve, parse, dirname } from 'path';
|
4
|
+
import path, { join, resolve, parse, dirname, isAbsolute } from 'path';
|
5
5
|
import express from 'express';
|
6
6
|
import fs2 from 'fs-extra';
|
7
7
|
import { WebpackInvocationError } from 'storybook/internal/server-errors';
|
@@ -10,11 +10,12 @@ import { globalsNameReferenceMap } from 'storybook/internal/preview/globals';
|
|
10
10
|
import { normalizeStories, loadPreviewOrConfigFile, handlebars, readTemplate, getBuilderOptions, stringifyProcessEnvs, isPreservingSymlinks } from 'storybook/internal/common';
|
11
11
|
import { dedent } from 'ts-dedent';
|
12
12
|
import fs from 'fs';
|
13
|
-
import { webpackIncludeRegexp } from '@storybook/core-webpack';
|
13
|
+
import { webpackIncludeRegexp, mergeConfigs } from '@storybook/core-webpack';
|
14
14
|
import { webpack } from '@storybook/addon-docs/dist/preset';
|
15
15
|
import { pluginTypeCheck } from '@rsbuild/plugin-type-check';
|
16
16
|
import { pluginHtmlMinifierTerser } from 'rsbuild-plugin-html-minifier-terser';
|
17
17
|
import { corePath } from 'storybook/core-path';
|
18
|
+
import { readFile } from 'fs/promises';
|
18
19
|
|
19
20
|
// ../../node_modules/.pnpm/pretty-hrtime@1.0.3/node_modules/pretty-hrtime/index.js
|
20
21
|
var require_pretty_hrtime = __commonJS({
|
@@ -454,6 +455,39 @@ var iframe_rsbuild_config_default = async (options) => {
|
|
454
455
|
});
|
455
456
|
return merged;
|
456
457
|
};
|
458
|
+
var getIsReactVersion18or19 = async (options) => {
|
459
|
+
const { legacyRootApi } = await options.presets.apply(
|
460
|
+
"frameworkOptions"
|
461
|
+
) || {};
|
462
|
+
if (legacyRootApi) {
|
463
|
+
return false;
|
464
|
+
}
|
465
|
+
const resolvedReact = await options.presets.apply(
|
466
|
+
"resolvedReact",
|
467
|
+
{}
|
468
|
+
);
|
469
|
+
const reactDom = resolvedReact.reactDom || dirname(__require.resolve("react-dom/package.json"));
|
470
|
+
if (!isAbsolute(reactDom)) {
|
471
|
+
return false;
|
472
|
+
}
|
473
|
+
const { version } = JSON.parse(
|
474
|
+
await readFile(join(reactDom, "package.json"), "utf-8")
|
475
|
+
);
|
476
|
+
return version.startsWith("18") || version.startsWith("19") || version.startsWith("0.0.0");
|
477
|
+
};
|
478
|
+
var applyReactShims = async (config, options) => {
|
479
|
+
const isReactVersion18 = await getIsReactVersion18or19(options);
|
480
|
+
if (isReactVersion18) {
|
481
|
+
return config;
|
482
|
+
}
|
483
|
+
return {
|
484
|
+
source: {
|
485
|
+
alias: {
|
486
|
+
"@storybook/react-dom-shim": "@storybook/react-dom-shim/dist/react-16"
|
487
|
+
}
|
488
|
+
}
|
489
|
+
};
|
490
|
+
};
|
457
491
|
|
458
492
|
// src/index.ts
|
459
493
|
var import_pretty_hrtime = __toESM(require_pretty_hrtime());
|
@@ -465,14 +499,16 @@ var executor = {
|
|
465
499
|
}
|
466
500
|
};
|
467
501
|
var rsbuild = async (_, options) => {
|
468
|
-
const defaultConfig = await iframe_rsbuild_config_default(options);
|
469
502
|
const { presets } = options;
|
503
|
+
let defaultConfig = await iframe_rsbuild_config_default(options);
|
504
|
+
const shimsConfig = await applyReactShims(defaultConfig, options);
|
505
|
+
defaultConfig = mergeConfigs(defaultConfig, shimsConfig);
|
470
506
|
const finalDefaultConfig = await presets.apply(
|
471
507
|
"rsbuildFinal",
|
472
508
|
defaultConfig,
|
473
509
|
options
|
474
510
|
);
|
475
|
-
return finalDefaultConfig;
|
511
|
+
return mergeConfigs(finalDefaultConfig, shimsConfig);
|
476
512
|
};
|
477
513
|
var getConfig = async (options) => {
|
478
514
|
const { presets } = options;
|