storybook-builder-rsbuild 0.0.6-beta.1 → 0.0.6-beta.3
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 +54 -8
- package/dist/index.mjs +44 -4
- package/package.json +1 -1
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");
|
@@ -460,6 +460,10 @@ var iframe_rsbuild_config_default = async (options) => {
|
|
460
460
|
config.optimization.runtimeChunk = true;
|
461
461
|
config.optimization.usedExports = options.build?.test?.disableTreeShaking ? false : isProd;
|
462
462
|
config.optimization.moduleIds = "named";
|
463
|
+
config.module ??= {};
|
464
|
+
config.module.parser ??= {};
|
465
|
+
config.module.parser.javascript ??= {};
|
466
|
+
config.module.parser.javascript.exportsPresence = false;
|
463
467
|
appendPlugins(
|
464
468
|
[
|
465
469
|
new rspack.ProvidePlugin({
|
@@ -515,7 +519,47 @@ var iframe_rsbuild_config_default = async (options) => {
|
|
515
519
|
|
516
520
|
// src/index.ts
|
517
521
|
var import_core_path = require("storybook/core-path");
|
522
|
+
|
523
|
+
// src/react-shims.ts
|
524
|
+
var import_path4 = require("path");
|
525
|
+
var import_promises = require("fs/promises");
|
526
|
+
var getIsReactVersion18or19 = async (options) => {
|
527
|
+
const { legacyRootApi } = await options.presets.apply(
|
528
|
+
"frameworkOptions"
|
529
|
+
) || {};
|
530
|
+
if (legacyRootApi) {
|
531
|
+
return false;
|
532
|
+
}
|
533
|
+
const resolvedReact = await options.presets.apply(
|
534
|
+
"resolvedReact",
|
535
|
+
{}
|
536
|
+
);
|
537
|
+
const reactDom = resolvedReact.reactDom || (0, import_path4.dirname)(require.resolve("react-dom/package.json"));
|
538
|
+
if (!(0, import_path4.isAbsolute)(reactDom)) {
|
539
|
+
return false;
|
540
|
+
}
|
541
|
+
const { version } = JSON.parse(
|
542
|
+
await (0, import_promises.readFile)((0, import_path4.join)(reactDom, "package.json"), "utf-8")
|
543
|
+
);
|
544
|
+
return version.startsWith("18") || version.startsWith("19") || version.startsWith("0.0.0");
|
545
|
+
};
|
546
|
+
var applyReactShims = async (config, options) => {
|
547
|
+
const isReactVersion18 = await getIsReactVersion18or19(options);
|
548
|
+
if (isReactVersion18) {
|
549
|
+
return config;
|
550
|
+
}
|
551
|
+
return {
|
552
|
+
source: {
|
553
|
+
alias: {
|
554
|
+
"@storybook/react-dom-shim": "@storybook/react-dom-shim/dist/react-16"
|
555
|
+
}
|
556
|
+
}
|
557
|
+
};
|
558
|
+
};
|
559
|
+
|
560
|
+
// src/index.ts
|
518
561
|
var import_pretty_hrtime = __toESM(require_pretty_hrtime());
|
562
|
+
var import_core2 = require("@rsbuild/core");
|
519
563
|
var printDuration = (startTime) => (0, import_pretty_hrtime.default)(process.hrtime(startTime)).replace(" ms", " milliseconds").replace(" s", " seconds").replace(" m", " minutes");
|
520
564
|
var executor = {
|
521
565
|
get: async (options) => {
|
@@ -524,14 +568,16 @@ var executor = {
|
|
524
568
|
}
|
525
569
|
};
|
526
570
|
var rsbuild = async (_, options) => {
|
527
|
-
const defaultConfig = await iframe_rsbuild_config_default(options);
|
528
571
|
const { presets } = options;
|
572
|
+
let defaultConfig = await iframe_rsbuild_config_default(options);
|
573
|
+
const shimsConfig = await applyReactShims(defaultConfig, options);
|
574
|
+
defaultConfig = (0, import_core2.mergeRsbuildConfig)(defaultConfig, shimsConfig);
|
529
575
|
const finalDefaultConfig = await presets.apply(
|
530
576
|
"rsbuildFinal",
|
531
577
|
defaultConfig,
|
532
578
|
options
|
533
579
|
);
|
534
|
-
return finalDefaultConfig;
|
580
|
+
return (0, import_core2.mergeRsbuildConfig)(finalDefaultConfig);
|
535
581
|
};
|
536
582
|
var getConfig = async (options) => {
|
537
583
|
const { presets } = options;
|
@@ -589,7 +635,7 @@ var start = async ({
|
|
589
635
|
error: new Error(`Missing Rsbuild build instance at runtime!`)
|
590
636
|
});
|
591
637
|
}
|
592
|
-
const previewResolvedDir = (0,
|
638
|
+
const previewResolvedDir = (0, import_path5.join)(import_core_path.corePath, "dist/preview");
|
593
639
|
const previewDirOrigin = previewResolvedDir;
|
594
640
|
router.use(
|
595
641
|
`/sb-preview`,
|
@@ -611,16 +657,16 @@ var build = async ({ options }) => {
|
|
611
657
|
cwd: process.cwd(),
|
612
658
|
rsbuildConfig: config
|
613
659
|
});
|
614
|
-
const previewResolvedDir = (0,
|
660
|
+
const previewResolvedDir = (0, import_path5.join)(import_core_path.corePath, "dist/preview");
|
615
661
|
const previewDirOrigin = previewResolvedDir;
|
616
|
-
const previewDirTarget = (0,
|
662
|
+
const previewDirTarget = (0, import_path5.join)(options.outputDir || "", `sb-preview`);
|
617
663
|
let stats;
|
618
664
|
rsbuildBuild.onAfterBuild((params) => {
|
619
665
|
stats = params.stats;
|
620
666
|
});
|
621
667
|
const previewFiles = import_fs_extra.default.copy(previewDirOrigin, previewDirTarget, {
|
622
668
|
filter: (src) => {
|
623
|
-
const { ext } = (0,
|
669
|
+
const { ext } = (0, import_path5.parse)(src);
|
624
670
|
if (ext) {
|
625
671
|
return ext === ".js";
|
626
672
|
}
|
@@ -633,7 +679,7 @@ var build = async ({ options }) => {
|
|
633
679
|
await Promise.all([rsbuildBuild.build(), previewFiles]);
|
634
680
|
return stats;
|
635
681
|
};
|
636
|
-
var corePresets = [(0,
|
682
|
+
var corePresets = [(0, import_path5.join)(__dirname, "./preview-preset.js")];
|
637
683
|
var previewMainTemplate = () => require.resolve("storybook-builder-rsbuild/templates/preview.ejs");
|
638
684
|
// Annotate the CommonJS export names for ESM import in node:
|
639
685
|
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
|
-
import {
|
4
|
-
import path, { join, resolve, parse, dirname } from 'path';
|
3
|
+
import { mergeRsbuildConfig, loadConfig } from '@rsbuild/core';
|
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';
|
@@ -15,6 +15,7 @@ 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({
|
@@ -402,6 +403,10 @@ var iframe_rsbuild_config_default = async (options) => {
|
|
402
403
|
config.optimization.runtimeChunk = true;
|
403
404
|
config.optimization.usedExports = options.build?.test?.disableTreeShaking ? false : isProd;
|
404
405
|
config.optimization.moduleIds = "named";
|
406
|
+
config.module ??= {};
|
407
|
+
config.module.parser ??= {};
|
408
|
+
config.module.parser.javascript ??= {};
|
409
|
+
config.module.parser.javascript.exportsPresence = false;
|
405
410
|
appendPlugins(
|
406
411
|
[
|
407
412
|
new rspack.ProvidePlugin({
|
@@ -454,6 +459,39 @@ var iframe_rsbuild_config_default = async (options) => {
|
|
454
459
|
});
|
455
460
|
return merged;
|
456
461
|
};
|
462
|
+
var getIsReactVersion18or19 = async (options) => {
|
463
|
+
const { legacyRootApi } = await options.presets.apply(
|
464
|
+
"frameworkOptions"
|
465
|
+
) || {};
|
466
|
+
if (legacyRootApi) {
|
467
|
+
return false;
|
468
|
+
}
|
469
|
+
const resolvedReact = await options.presets.apply(
|
470
|
+
"resolvedReact",
|
471
|
+
{}
|
472
|
+
);
|
473
|
+
const reactDom = resolvedReact.reactDom || dirname(__require.resolve("react-dom/package.json"));
|
474
|
+
if (!isAbsolute(reactDom)) {
|
475
|
+
return false;
|
476
|
+
}
|
477
|
+
const { version } = JSON.parse(
|
478
|
+
await readFile(join(reactDom, "package.json"), "utf-8")
|
479
|
+
);
|
480
|
+
return version.startsWith("18") || version.startsWith("19") || version.startsWith("0.0.0");
|
481
|
+
};
|
482
|
+
var applyReactShims = async (config, options) => {
|
483
|
+
const isReactVersion18 = await getIsReactVersion18or19(options);
|
484
|
+
if (isReactVersion18) {
|
485
|
+
return config;
|
486
|
+
}
|
487
|
+
return {
|
488
|
+
source: {
|
489
|
+
alias: {
|
490
|
+
"@storybook/react-dom-shim": "@storybook/react-dom-shim/dist/react-16"
|
491
|
+
}
|
492
|
+
}
|
493
|
+
};
|
494
|
+
};
|
457
495
|
|
458
496
|
// src/index.ts
|
459
497
|
var import_pretty_hrtime = __toESM(require_pretty_hrtime());
|
@@ -465,14 +503,16 @@ var executor = {
|
|
465
503
|
}
|
466
504
|
};
|
467
505
|
var rsbuild = async (_, options) => {
|
468
|
-
const defaultConfig = await iframe_rsbuild_config_default(options);
|
469
506
|
const { presets } = options;
|
507
|
+
let defaultConfig = await iframe_rsbuild_config_default(options);
|
508
|
+
const shimsConfig = await applyReactShims(defaultConfig, options);
|
509
|
+
defaultConfig = mergeRsbuildConfig(defaultConfig, shimsConfig);
|
470
510
|
const finalDefaultConfig = await presets.apply(
|
471
511
|
"rsbuildFinal",
|
472
512
|
defaultConfig,
|
473
513
|
options
|
474
514
|
);
|
475
|
-
return finalDefaultConfig;
|
515
|
+
return mergeRsbuildConfig(finalDefaultConfig);
|
476
516
|
};
|
477
517
|
var getConfig = async (options) => {
|
478
518
|
const { presets } = options;
|