storybook-builder-rsbuild 2.1.5 → 3.0.0-beta.1
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/compiled/@storybook/core-webpack/index.d.ts +56 -0
- package/compiled/@storybook/core-webpack/index.js +360 -0
- package/compiled/@storybook/core-webpack/package.json +1 -0
- package/dist/_node-chunks/chunk-MIMCYZFR.js +45 -0
- package/dist/index.d.ts +3 -72
- package/dist/index.js +459 -406
- package/dist/loaders/export-order-loader.js +31 -52
- package/dist/preview-preset.js +17 -39
- package/package.json +18 -30
- package/dist/chunk-TTFRSOOU.mjs +0 -34
- package/dist/index.mjs +0 -667
- package/dist/loaders/export-order-loader.d.ts +0 -5
- package/dist/loaders/export-order-loader.mjs +0 -49
- package/dist/preview-preset.d.ts +0 -3
package/dist/index.js
CHANGED
|
@@ -1,213 +1,376 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
for (let key of __getOwnPropNames(from))
|
|
18
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
|
-
}
|
|
21
|
-
return to;
|
|
22
|
-
};
|
|
23
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
-
mod
|
|
30
|
-
));
|
|
31
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
import CJS_COMPAT_NODE_URL_c7aef05d0183c9d0 from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_c7aef05d0183c9d0 from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_c7aef05d0183c9d0 from "node:module";
|
|
4
|
+
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_c7aef05d0183c9d0.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_c7aef05d0183c9d0.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_c7aef05d0183c9d0.createRequire(import.meta.url);
|
|
8
|
+
|
|
9
|
+
// ------------------------------------------------------------
|
|
10
|
+
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
11
|
+
// ------------------------------------------------------------
|
|
12
|
+
import {
|
|
13
|
+
__commonJS,
|
|
14
|
+
__require,
|
|
15
|
+
__toESM
|
|
16
|
+
} from "./_node-chunks/chunk-MIMCYZFR.js";
|
|
32
17
|
|
|
33
18
|
// ../../node_modules/.pnpm/pretty-hrtime@1.0.3/node_modules/pretty-hrtime/index.js
|
|
34
19
|
var require_pretty_hrtime = __commonJS({
|
|
35
|
-
"../../node_modules/.pnpm/pretty-hrtime@1.0.3/node_modules/pretty-hrtime/index.js"(exports,
|
|
20
|
+
"../../node_modules/.pnpm/pretty-hrtime@1.0.3/node_modules/pretty-hrtime/index.js"(exports, module) {
|
|
36
21
|
"use strict";
|
|
37
|
-
var minimalDesc = ["h", "min", "s", "ms", "\u03BCs", "ns"];
|
|
38
|
-
|
|
39
|
-
var convert = [60 * 60, 60, 1, 1e6, 1e3, 1];
|
|
40
|
-
module2.exports = function(source, opts) {
|
|
22
|
+
var minimalDesc = ["h", "min", "s", "ms", "\u03BCs", "ns"], verboseDesc = ["hour", "minute", "second", "millisecond", "microsecond", "nanosecond"], convert = [3600, 60, 1, 1e6, 1e3, 1];
|
|
23
|
+
module.exports = function(source, opts) {
|
|
41
24
|
var verbose, precise, i, spot, sourceAtStep, valAtStep, decimals, strAtStep, results, totalSeconds;
|
|
42
|
-
verbose =
|
|
43
|
-
precise = false;
|
|
44
|
-
if (opts) {
|
|
45
|
-
verbose = opts.verbose || false;
|
|
46
|
-
precise = opts.precise || false;
|
|
47
|
-
}
|
|
48
|
-
if (!Array.isArray(source) || source.length !== 2) {
|
|
25
|
+
if (verbose = !1, precise = !1, opts && (verbose = opts.verbose || !1, precise = opts.precise || !1), !Array.isArray(source) || source.length !== 2 || typeof source[0] != "number" || typeof source[1] != "number")
|
|
49
26
|
return "";
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return "";
|
|
53
|
-
}
|
|
54
|
-
if (source[1] < 0) {
|
|
55
|
-
totalSeconds = source[0] + source[1] / 1e9;
|
|
56
|
-
source[0] = parseInt(totalSeconds);
|
|
57
|
-
source[1] = parseFloat((totalSeconds % 1).toPrecision(9)) * 1e9;
|
|
58
|
-
}
|
|
59
|
-
results = "";
|
|
60
|
-
for (i = 0; i < 6; i++) {
|
|
61
|
-
spot = i < 3 ? 0 : 1;
|
|
62
|
-
sourceAtStep = source[spot];
|
|
63
|
-
if (i !== 3 && i !== 0) {
|
|
64
|
-
sourceAtStep = sourceAtStep % convert[i - 1];
|
|
65
|
-
}
|
|
66
|
-
if (i === 2) {
|
|
67
|
-
sourceAtStep += source[1] / 1e9;
|
|
68
|
-
}
|
|
69
|
-
valAtStep = sourceAtStep / convert[i];
|
|
70
|
-
if (valAtStep >= 1) {
|
|
71
|
-
if (verbose) {
|
|
72
|
-
valAtStep = Math.floor(valAtStep);
|
|
73
|
-
}
|
|
74
|
-
if (!precise) {
|
|
75
|
-
decimals = valAtStep >= 10 ? 0 : 2;
|
|
76
|
-
strAtStep = valAtStep.toFixed(decimals);
|
|
77
|
-
} else {
|
|
78
|
-
strAtStep = valAtStep.toString();
|
|
79
|
-
}
|
|
80
|
-
if (strAtStep.indexOf(".") > -1 && strAtStep[strAtStep.length - 1] === "0") {
|
|
81
|
-
strAtStep = strAtStep.replace(/\.?0+$/, "");
|
|
82
|
-
}
|
|
83
|
-
if (results) {
|
|
84
|
-
results += " ";
|
|
85
|
-
}
|
|
86
|
-
results += strAtStep;
|
|
87
|
-
if (verbose) {
|
|
88
|
-
results += " " + verboseDesc[i];
|
|
89
|
-
if (strAtStep !== "1") {
|
|
90
|
-
results += "s";
|
|
91
|
-
}
|
|
92
|
-
} else {
|
|
93
|
-
results += " " + minimalDesc[i];
|
|
94
|
-
}
|
|
95
|
-
if (!verbose) {
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
27
|
+
for (source[1] < 0 && (totalSeconds = source[0] + source[1] / 1e9, source[0] = parseInt(totalSeconds), source[1] = parseFloat((totalSeconds % 1).toPrecision(9)) * 1e9), results = "", i = 0; i < 6 && (spot = i < 3 ? 0 : 1, sourceAtStep = source[spot], i !== 3 && i !== 0 && (sourceAtStep = sourceAtStep % convert[i - 1]), i === 2 && (sourceAtStep += source[1] / 1e9), valAtStep = sourceAtStep / convert[i], !(valAtStep >= 1 && (verbose && (valAtStep = Math.floor(valAtStep)), precise ? strAtStep = valAtStep.toString() : (decimals = valAtStep >= 10 ? 0 : 2, strAtStep = valAtStep.toFixed(decimals)), strAtStep.indexOf(".") > -1 && strAtStep[strAtStep.length - 1] === "0" && (strAtStep = strAtStep.replace(/\.?0+$/, "")), results && (results += " "), results += strAtStep, verbose ? (results += " " + verboseDesc[i], strAtStep !== "1" && (results += "s")) : results += " " + minimalDesc[i], !verbose))); i++)
|
|
28
|
+
;
|
|
100
29
|
return results;
|
|
101
30
|
};
|
|
102
31
|
}
|
|
103
32
|
});
|
|
104
33
|
|
|
105
34
|
// src/index.ts
|
|
106
|
-
var
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
previewMainTemplate: () => previewMainTemplate,
|
|
115
|
-
printDuration: () => printDuration,
|
|
116
|
-
start: () => start
|
|
117
|
-
});
|
|
118
|
-
module.exports = __toCommonJS(src_exports);
|
|
119
|
-
var import_node_net = require("net");
|
|
120
|
-
var import_node_path4 = require("path");
|
|
121
|
-
var rsbuildReal = __toESM(require("@rsbuild/core"));
|
|
122
|
-
var import_fs_extra = __toESM(require("fs-extra"));
|
|
123
|
-
var import_pretty_hrtime = __toESM(require_pretty_hrtime());
|
|
124
|
-
var import_sirv = __toESM(require("sirv"));
|
|
125
|
-
var import_common3 = require("storybook/internal/common");
|
|
126
|
-
var import_server_errors = require("storybook/internal/server-errors");
|
|
35
|
+
var import_pretty_hrtime = __toESM(require_pretty_hrtime(), 1);
|
|
36
|
+
import { createServer } from "node:net";
|
|
37
|
+
import { dirname as dirname3, join as join4, parse } from "node:path";
|
|
38
|
+
import * as rsbuildReal from "@rsbuild/core";
|
|
39
|
+
import fs from "fs-extra";
|
|
40
|
+
import sirv from "sirv";
|
|
41
|
+
import { getPresets, resolveAddonName } from "storybook/internal/common";
|
|
42
|
+
import { WebpackInvocationError } from "storybook/internal/server-errors";
|
|
127
43
|
|
|
128
44
|
// src/preview/iframe-rsbuild.config.ts
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
45
|
+
import { dirname, join as join2, resolve as resolve2 } from "node:path";
|
|
46
|
+
import { loadConfig, mergeRsbuildConfig } from "@rsbuild/core";
|
|
47
|
+
import { pluginTypeCheck } from "@rsbuild/plugin-type-check";
|
|
48
|
+
import CaseSensitivePathsPlugin from "case-sensitive-paths-webpack-plugin";
|
|
49
|
+
import { pluginHtmlMinifierTerser } from "rsbuild-plugin-html-minifier-terser";
|
|
50
|
+
import {
|
|
51
|
+
getBuilderOptions as getBuilderOptions2,
|
|
52
|
+
isPreservingSymlinks,
|
|
53
|
+
normalizeStories as normalizeStories2,
|
|
54
|
+
stringifyProcessEnvs
|
|
55
|
+
} from "storybook/internal/common";
|
|
56
|
+
import { globalsNameReferenceMap } from "storybook/internal/preview/globals";
|
|
57
|
+
import { dedent } from "ts-dedent";
|
|
138
58
|
|
|
139
59
|
// src/preview/virtual-module-mapping.ts
|
|
140
|
-
|
|
141
|
-
var import_core_webpack = require("@storybook/core-webpack");
|
|
60
|
+
import { join, resolve } from "node:path";
|
|
142
61
|
|
|
143
62
|
// ../../node_modules/.pnpm/slash@5.1.0/node_modules/slash/index.js
|
|
144
63
|
function slash(path) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
64
|
+
return path.startsWith("\\\\?\\") ? path : path.replace(/\\/g, "/");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// src/preview/virtual-module-mapping.ts
|
|
68
|
+
import {
|
|
69
|
+
getBuilderOptions,
|
|
70
|
+
loadPreviewOrConfigFile,
|
|
71
|
+
normalizeStories,
|
|
72
|
+
readTemplate
|
|
73
|
+
} from "storybook/internal/common";
|
|
74
|
+
|
|
75
|
+
// compiled/@storybook/core-webpack/index.js
|
|
76
|
+
import { createRequire as __WEBPACK_EXTERNAL_createRequire } from "module";
|
|
77
|
+
import * as __WEBPACK_EXTERNAL_MODULE_storybook_internal_common_7991bda6__ from "storybook/internal/common";
|
|
78
|
+
import * as __WEBPACK_EXTERNAL_MODULE_storybook_internal_node_logger_87de4309__ from "storybook/internal/node-logger";
|
|
79
|
+
var __webpack_modules__ = {
|
|
80
|
+
980: (__unused_webpack_module, exports) => {
|
|
81
|
+
var __webpack_unused_export__;
|
|
82
|
+
__webpack_unused_export__ = { value: !0 }, exports.TW = void 0;
|
|
83
|
+
function dedent2(templ) {
|
|
84
|
+
for (var values = [], _i = 1; _i < arguments.length; _i++)
|
|
85
|
+
values[_i - 1] = arguments[_i];
|
|
86
|
+
var strings = Array.from(typeof templ == "string" ? [templ] : templ);
|
|
87
|
+
strings[strings.length - 1] = strings[strings.length - 1].replace(
|
|
88
|
+
/\r?\n([\t ]*)$/,
|
|
89
|
+
""
|
|
90
|
+
);
|
|
91
|
+
var indentLengths = strings.reduce(function(arr, str) {
|
|
92
|
+
var matches = str.match(/\n([\t ]+|(?!\s).)/g);
|
|
93
|
+
return matches ? arr.concat(
|
|
94
|
+
matches.map(function(match) {
|
|
95
|
+
var _a, _b;
|
|
96
|
+
return (_b = (_a = match.match(/[\t ]/g)) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
|
|
97
|
+
})
|
|
98
|
+
) : arr;
|
|
99
|
+
}, []);
|
|
100
|
+
if (indentLengths.length) {
|
|
101
|
+
var pattern_1 = new RegExp(
|
|
102
|
+
`
|
|
103
|
+
[ ]{` + Math.min.apply(Math, indentLengths) + "}",
|
|
104
|
+
"g"
|
|
105
|
+
);
|
|
106
|
+
strings = strings.map(function(str) {
|
|
107
|
+
return str.replace(pattern_1, `
|
|
108
|
+
`);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
strings[0] = strings[0].replace(/^\r?\n/, "");
|
|
112
|
+
var string = strings[0];
|
|
113
|
+
return values.forEach(function(value, i) {
|
|
114
|
+
var endentations = string.match(/(?:^|\n)( *)$/), endentation = endentations ? endentations[1] : "", indentedValue = value;
|
|
115
|
+
typeof value == "string" && value.includes(`
|
|
116
|
+
`) && (indentedValue = String(value).split(`
|
|
117
|
+
`).map(function(str, i2) {
|
|
118
|
+
return i2 === 0 ? str : "" + endentation + str;
|
|
119
|
+
}).join(`
|
|
120
|
+
`)), string += indentedValue + strings[i + 1];
|
|
121
|
+
}), string;
|
|
122
|
+
}
|
|
123
|
+
exports.TW = dedent2, __webpack_unused_export__ = dedent2;
|
|
124
|
+
}
|
|
125
|
+
}, __webpack_module_cache__ = {};
|
|
126
|
+
function __nccwpck_require__(moduleId) {
|
|
127
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
128
|
+
if (cachedModule !== void 0)
|
|
129
|
+
return cachedModule.exports;
|
|
130
|
+
var module = __webpack_module_cache__[moduleId] = { exports: {} }, threw = !0;
|
|
131
|
+
try {
|
|
132
|
+
__webpack_modules__[moduleId](module, module.exports, __nccwpck_require__), threw = !1;
|
|
133
|
+
} finally {
|
|
134
|
+
threw && delete __webpack_module_cache__[moduleId];
|
|
135
|
+
}
|
|
136
|
+
return module.exports;
|
|
137
|
+
}
|
|
138
|
+
__nccwpck_require__.d = (exports, definition) => {
|
|
139
|
+
for (var key in definition)
|
|
140
|
+
__nccwpck_require__.o(definition, key) && !__nccwpck_require__.o(exports, key) && Object.defineProperty(exports, key, {
|
|
141
|
+
enumerable: !0,
|
|
142
|
+
get: definition[key]
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
__nccwpck_require__.o = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
146
|
+
typeof __nccwpck_require__ < "u" && (__nccwpck_require__.ab = new URL(".", import.meta.url).pathname.slice(
|
|
147
|
+
import.meta.url.match(/^file:\/\/\/\w:/) ? 1 : 0,
|
|
148
|
+
-1
|
|
149
|
+
) + "/");
|
|
150
|
+
var __webpack_exports__ = {};
|
|
151
|
+
__nccwpck_require__.d(__webpack_exports__, {
|
|
152
|
+
il: () => checkWebpackVersion,
|
|
153
|
+
Tu: () => loadCustomWebpackConfig,
|
|
154
|
+
SV: () => mergeConfigs,
|
|
155
|
+
T1: () => toImportFn,
|
|
156
|
+
i8: () => toImportFnPart,
|
|
157
|
+
sg: () => toRequireContext,
|
|
158
|
+
HO: () => toRequireContextString,
|
|
159
|
+
hO: () => webpackIncludeRegexp
|
|
160
|
+
});
|
|
161
|
+
var external_node_url_namespaceObject = __WEBPACK_EXTERNAL_createRequire(
|
|
162
|
+
import.meta.url
|
|
163
|
+
)("node:url"), external_node_path_namespaceObject = __WEBPACK_EXTERNAL_createRequire(
|
|
164
|
+
import.meta.url
|
|
165
|
+
)("node:path"), external_node_module_namespaceObject = __WEBPACK_EXTERNAL_createRequire(
|
|
166
|
+
import.meta.url
|
|
167
|
+
)("node:module"), x = (y) => {
|
|
168
|
+
var x2 = {};
|
|
169
|
+
return __nccwpck_require__.d(x2, y), x2;
|
|
170
|
+
};
|
|
171
|
+
var common_namespaceObject = x({
|
|
172
|
+
globToRegexp: () => __WEBPACK_EXTERNAL_MODULE_storybook_internal_common_7991bda6__.globToRegexp,
|
|
173
|
+
serverRequire: () => __WEBPACK_EXTERNAL_MODULE_storybook_internal_common_7991bda6__.serverRequire
|
|
174
|
+
}), node_logger_x = (y) => {
|
|
175
|
+
var x2 = {};
|
|
176
|
+
return __nccwpck_require__.d(x2, y), x2;
|
|
177
|
+
};
|
|
178
|
+
var node_logger_namespaceObject = node_logger_x({
|
|
179
|
+
logger: () => __WEBPACK_EXTERNAL_MODULE_storybook_internal_node_logger_87de4309__.logger
|
|
180
|
+
}), dist = __nccwpck_require__(980), dist_filename = external_node_url_namespaceObject.fileURLToPath(
|
|
181
|
+
import.meta.url
|
|
182
|
+
), dist_dirname = external_node_path_namespaceObject.dirname(dist_filename), dist_require = external_node_module_namespaceObject.createRequire(
|
|
183
|
+
import.meta.url
|
|
184
|
+
), __defProp = Object.defineProperty, __name = (target, value) => __defProp(target, "name", { value, configurable: !0 }), webpackConfigs = ["webpack.config", "webpackfile"], loadCustomWebpackConfig = __name(
|
|
185
|
+
async (configDir) => (0, common_namespaceObject.serverRequire)(
|
|
186
|
+
webpackConfigs.map(
|
|
187
|
+
(configName) => (0, external_node_path_namespaceObject.resolve)(configDir, configName)
|
|
188
|
+
)
|
|
189
|
+
),
|
|
190
|
+
"loadCustomWebpackConfig"
|
|
191
|
+
), checkWebpackVersion = __name((webpack, specifier, caption) => {
|
|
192
|
+
if (!webpack.version) {
|
|
193
|
+
node_logger_namespaceObject.logger.info(
|
|
194
|
+
"Skipping webpack version check, no version available"
|
|
195
|
+
);
|
|
196
|
+
return;
|
|
148
197
|
}
|
|
149
|
-
|
|
198
|
+
webpack.version !== specifier && node_logger_namespaceObject.logger.warn((0, dist.TW)`
|
|
199
|
+
Unexpected webpack version in ${caption}:
|
|
200
|
+
- Received '${webpack.version}'
|
|
201
|
+
- Expected '${specifier}'
|
|
202
|
+
|
|
203
|
+
If you're using Webpack 5 in SB6.2 and upgrading, consider: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#webpack-5-manager-build
|
|
204
|
+
|
|
205
|
+
For more info about Webpack 5 support: https://gist.github.com/shilman/8856ea1786dcd247139b47b270912324#troubleshooting
|
|
206
|
+
`);
|
|
207
|
+
}, "checkWebpackVersion");
|
|
208
|
+
function mergePluginsField(defaultPlugins = [], customPlugins = []) {
|
|
209
|
+
return [...defaultPlugins, ...customPlugins];
|
|
210
|
+
}
|
|
211
|
+
__name(mergePluginsField, "mergePluginsField");
|
|
212
|
+
function mergeRulesField(defaultRules = [], customRules = []) {
|
|
213
|
+
return [...defaultRules, ...customRules];
|
|
214
|
+
}
|
|
215
|
+
__name(mergeRulesField, "mergeRulesField");
|
|
216
|
+
function mergeExtensionsField({ extensions: defaultExtensions = [] }, { extensions: customExtensions = [] }) {
|
|
217
|
+
return [...defaultExtensions, ...customExtensions];
|
|
218
|
+
}
|
|
219
|
+
__name(mergeExtensionsField, "mergeExtensionsField");
|
|
220
|
+
function mergeAliasField({ alias: defaultAlias = {} }, { alias: customAlias = {} }) {
|
|
221
|
+
return { ...defaultAlias, ...customAlias };
|
|
222
|
+
}
|
|
223
|
+
__name(mergeAliasField, "mergeAliasField");
|
|
224
|
+
function mergeModuleField(a, b) {
|
|
225
|
+
return { ...a, ...b, rules: mergeRulesField(a.rules || [], b.rules || []) };
|
|
226
|
+
}
|
|
227
|
+
__name(mergeModuleField, "mergeModuleField");
|
|
228
|
+
function mergeResolveField({ resolve: defaultResolve = {} }, { resolve: customResolve = {} }) {
|
|
229
|
+
return {
|
|
230
|
+
...defaultResolve,
|
|
231
|
+
...customResolve,
|
|
232
|
+
alias: mergeAliasField(defaultResolve, customResolve),
|
|
233
|
+
extensions: mergeExtensionsField(defaultResolve, customResolve)
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
__name(mergeResolveField, "mergeResolveField");
|
|
237
|
+
function mergeOptimizationField({ optimization: defaultOptimization = {} }, { optimization: customOptimization = {} }) {
|
|
238
|
+
return { ...defaultOptimization, ...customOptimization };
|
|
239
|
+
}
|
|
240
|
+
__name(mergeOptimizationField, "mergeOptimizationField");
|
|
241
|
+
function mergeConfigs(config, customConfig) {
|
|
242
|
+
return {
|
|
243
|
+
...customConfig,
|
|
244
|
+
...config,
|
|
245
|
+
devtool: customConfig.devtool || config.devtool,
|
|
246
|
+
plugins: mergePluginsField(config.plugins, customConfig.plugins),
|
|
247
|
+
module: mergeModuleField(config.module || {}, customConfig.module || {}),
|
|
248
|
+
resolve: mergeResolveField(config, customConfig),
|
|
249
|
+
optimization: mergeOptimizationField(config, customConfig)
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
__name(mergeConfigs, "mergeConfigs");
|
|
253
|
+
function importPipeline() {
|
|
254
|
+
let importGate = Promise.resolve();
|
|
255
|
+
return async (importFn) => {
|
|
256
|
+
await importGate;
|
|
257
|
+
let moduleExportsPromise = importFn();
|
|
258
|
+
return importGate = importGate.then(async () => {
|
|
259
|
+
await moduleExportsPromise;
|
|
260
|
+
}), moduleExportsPromise;
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
__name(importPipeline, "importPipeline");
|
|
264
|
+
function adjustRegexToExcludeNodeModules(originalRegex) {
|
|
265
|
+
let originalRegexString = originalRegex.source, startsWithCaret = originalRegexString.startsWith("^"), excludeNodeModulesPattern = startsWithCaret ? "(?!.*node_modules)" : "^(?!.*node_modules)", adjustedRegexString = startsWithCaret ? `^${excludeNodeModulesPattern}${originalRegexString.substring(1)}` : excludeNodeModulesPattern + originalRegexString;
|
|
266
|
+
return new RegExp(adjustedRegexString);
|
|
267
|
+
}
|
|
268
|
+
__name(adjustRegexToExcludeNodeModules, "adjustRegexToExcludeNodeModules");
|
|
269
|
+
function webpackIncludeRegexp(specifier) {
|
|
270
|
+
let { directory, files } = specifier, directoryWithoutLeadingDots = directory.replace(/^(\.+\/)+/, "/"), webpackIncludeGlob = [".", ".."].includes(directory) ? files : `${directoryWithoutLeadingDots}/${files}`, webpackIncludeRegexpWithCaret = webpackIncludeGlob.includes(
|
|
271
|
+
"node_modules"
|
|
272
|
+
) ? (0, common_namespaceObject.globToRegexp)(webpackIncludeGlob) : adjustRegexToExcludeNodeModules(
|
|
273
|
+
(0, common_namespaceObject.globToRegexp)(webpackIncludeGlob)
|
|
274
|
+
);
|
|
275
|
+
return new RegExp(webpackIncludeRegexpWithCaret.source.replace(/^\^/, ""));
|
|
276
|
+
}
|
|
277
|
+
__name(webpackIncludeRegexp, "webpackIncludeRegexp");
|
|
278
|
+
function toImportFnPart(specifier) {
|
|
279
|
+
let { directory, importPathMatcher } = specifier;
|
|
280
|
+
return (0, dist.TW)`
|
|
281
|
+
async (path) => {
|
|
282
|
+
if (!${importPathMatcher}.exec(path)) {
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const pathRemainder = path.substring(${directory.length + 1});
|
|
287
|
+
return import(
|
|
288
|
+
/* webpackChunkName: "[request]" */
|
|
289
|
+
/* webpackInclude: ${webpackIncludeRegexp(specifier)} */
|
|
290
|
+
'${directory}/' + pathRemainder
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
`;
|
|
150
295
|
}
|
|
296
|
+
__name(toImportFnPart, "toImportFnPart");
|
|
297
|
+
function toImportFn(stories, { needPipelinedImport } = {}) {
|
|
298
|
+
let pipelinedImport = "const pipeline = (x) => x();";
|
|
299
|
+
return needPipelinedImport && (pipelinedImport = `
|
|
300
|
+
const importPipeline = ${importPipeline};
|
|
301
|
+
const pipeline = importPipeline();
|
|
302
|
+
`), (0, dist.TW)`
|
|
303
|
+
${pipelinedImport}
|
|
304
|
+
|
|
305
|
+
const importers = [
|
|
306
|
+
${stories.map(toImportFnPart).join(`,
|
|
307
|
+
`)}
|
|
308
|
+
];
|
|
309
|
+
|
|
310
|
+
export async function importFn(path) {
|
|
311
|
+
for (let i = 0; i < importers.length; i++) {
|
|
312
|
+
const moduleExports = await pipeline(() => importers[i](path));
|
|
313
|
+
if (moduleExports) {
|
|
314
|
+
return moduleExports;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
`;
|
|
319
|
+
}
|
|
320
|
+
__name(toImportFn, "toImportFn");
|
|
321
|
+
var toRequireContext = __name((specifier) => {
|
|
322
|
+
let { directory, files } = specifier, match = (0, common_namespaceObject.globToRegexp)(`./${files}`);
|
|
323
|
+
return {
|
|
324
|
+
path: directory,
|
|
325
|
+
recursive: files.includes("**") || files.split("/").length > 1,
|
|
326
|
+
match
|
|
327
|
+
};
|
|
328
|
+
}, "toRequireContext"), toRequireContextString = __name((specifier) => {
|
|
329
|
+
let { path: p, recursive: r, match: m } = toRequireContext(specifier);
|
|
330
|
+
return `require.context('${p}', ${r}, ${m})`;
|
|
331
|
+
}, "toRequireContextString"), __webpack_exports__checkWebpackVersion = __webpack_exports__.il, __webpack_exports__loadCustomWebpackConfig = __webpack_exports__.Tu, __webpack_exports__mergeConfigs = __webpack_exports__.SV, __webpack_exports__toImportFn = __webpack_exports__.T1, __webpack_exports__toImportFnPart = __webpack_exports__.i8, __webpack_exports__toRequireContext = __webpack_exports__.sg, __webpack_exports__toRequireContextString = __webpack_exports__.HO, __webpack_exports__webpackIncludeRegexp = __webpack_exports__.hO;
|
|
151
332
|
|
|
152
333
|
// src/preview/virtual-module-mapping.ts
|
|
153
|
-
var import_common = require("storybook/internal/common");
|
|
154
334
|
var getVirtualModules = async (options) => {
|
|
155
|
-
|
|
156
|
-
const builderOptions = await (0, import_common.getBuilderOptions)(options);
|
|
157
|
-
const workingDir = process.cwd();
|
|
158
|
-
const isProd = options.configType === "PRODUCTION";
|
|
159
|
-
const nonNormalizedStories = await options.presets.apply("stories", []);
|
|
160
|
-
const entries = [];
|
|
161
|
-
const stories = (0, import_common.normalizeStories)(nonNormalizedStories, {
|
|
335
|
+
let virtualModules = {}, builderOptions = await getBuilderOptions(options), workingDir = process.cwd(), isProd = options.configType === "PRODUCTION", nonNormalizedStories = await options.presets.apply("stories", []), entries = [], stories = normalizeStories(nonNormalizedStories, {
|
|
162
336
|
configDir: options.configDir,
|
|
163
337
|
workingDir
|
|
164
|
-
})
|
|
165
|
-
const previewAnnotations = [
|
|
338
|
+
}), previewAnnotations = [
|
|
166
339
|
...(await options.presets.apply(
|
|
167
340
|
"previewAnnotations",
|
|
168
341
|
[],
|
|
169
342
|
options
|
|
170
|
-
)).map((entry) =>
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
return slash(entry);
|
|
175
|
-
}),
|
|
176
|
-
(0, import_common.loadPreviewOrConfigFile)(options)
|
|
177
|
-
].filter(Boolean);
|
|
178
|
-
const storiesFilename = "storybook-stories.js";
|
|
179
|
-
const storiesPath = (0, import_node_path.resolve)((0, import_node_path.join)(workingDir, storiesFilename));
|
|
180
|
-
const needPipelinedImport = !!builderOptions.lazyCompilation && !isProd;
|
|
181
|
-
virtualModules[storiesPath] = (0, import_core_webpack.toImportFn)(stories, {
|
|
343
|
+
)).map((entry) => typeof entry == "object" ? entry.absolute : slash(entry)),
|
|
344
|
+
loadPreviewOrConfigFile(options)
|
|
345
|
+
].filter(Boolean), storiesFilename = "storybook-stories.js", storiesPath = resolve(join(workingDir, storiesFilename)), needPipelinedImport = !!builderOptions.lazyCompilation && !isProd;
|
|
346
|
+
virtualModules[storiesPath] = __webpack_exports__toImportFn(stories, {
|
|
182
347
|
needPipelinedImport
|
|
183
348
|
});
|
|
184
|
-
|
|
185
|
-
virtualModules[configEntryPath] = (await
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
349
|
+
let configEntryPath = resolve(join(workingDir, "storybook-config-entry.js"));
|
|
350
|
+
return virtualModules[configEntryPath] = (await readTemplate(
|
|
351
|
+
__require.resolve(
|
|
352
|
+
"storybook-builder-rsbuild/templates/virtualModuleModernEntry.js"
|
|
353
|
+
)
|
|
354
|
+
)).replaceAll("'{{storiesFilename}}'", `'./${storiesFilename}'`).replaceAll(
|
|
355
|
+
"'{{previewAnnotations}}'",
|
|
189
356
|
previewAnnotations.filter(Boolean).map((entry) => `'${entry}'`).join(",")
|
|
190
357
|
).replaceAll(
|
|
191
|
-
|
|
358
|
+
"'{{previewAnnotations_requires}}'",
|
|
192
359
|
previewAnnotations.filter(Boolean).map((entry) => `require('${entry}')`).join(",")
|
|
193
|
-
).replace(/\\/g, "\\\\")
|
|
194
|
-
entries.push(configEntryPath);
|
|
195
|
-
return {
|
|
360
|
+
).replace(/\\/g, "\\\\"), entries.push(configEntryPath), {
|
|
196
361
|
virtualModules,
|
|
197
362
|
entries
|
|
198
363
|
};
|
|
199
364
|
};
|
|
200
365
|
|
|
201
366
|
// src/preview/iframe-rsbuild.config.ts
|
|
202
|
-
var getAbsolutePath = (input) =>
|
|
203
|
-
var maybeGetAbsolutePath = (input) => {
|
|
367
|
+
var getAbsolutePath = (input) => dirname(__require.resolve(join2(input, "package.json"))), maybeGetAbsolutePath = (input) => {
|
|
204
368
|
try {
|
|
205
369
|
return getAbsolutePath(input);
|
|
206
|
-
} catch
|
|
207
|
-
return
|
|
370
|
+
} catch {
|
|
371
|
+
return !1;
|
|
208
372
|
}
|
|
209
|
-
}
|
|
210
|
-
var builtInResolveExtensions = [
|
|
373
|
+
}, builtInResolveExtensions = [
|
|
211
374
|
".mjs",
|
|
212
375
|
".js",
|
|
213
376
|
".jsx",
|
|
@@ -215,17 +378,16 @@ var builtInResolveExtensions = [
|
|
|
215
378
|
".tsx",
|
|
216
379
|
".json",
|
|
217
380
|
".cjs"
|
|
218
|
-
]
|
|
219
|
-
var globalPath = maybeGetAbsolutePath("@storybook/global");
|
|
220
|
-
var storybookPaths = {
|
|
381
|
+
], globalPath = maybeGetAbsolutePath("@storybook/global"), storybookPaths = {
|
|
221
382
|
// biome-ignore lint/complexity/useLiteralKeys: <explanation>
|
|
222
|
-
...globalPath ? {
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
383
|
+
...globalPath ? { "@storybook/global": globalPath } : {}
|
|
384
|
+
}, iframe_rsbuild_config_default = async (options, extraWebpackConfig) => {
|
|
385
|
+
let { rsbuildConfigPath, addonDocs } = await getBuilderOptions2(options), webpackConfigFromPresets = await options.presets.apply("webpack", {}, options);
|
|
386
|
+
addonDocs && console.warn(
|
|
387
|
+
"`addonDocs` option is deprecated and will be removed in future versions. Please use `@storybook/addon-docs` option instead."
|
|
388
|
+
);
|
|
389
|
+
let {
|
|
390
|
+
outputDir = join2(".", "public"),
|
|
229
391
|
quiet,
|
|
230
392
|
packageJson,
|
|
231
393
|
configType,
|
|
@@ -233,10 +395,7 @@ var iframe_rsbuild_config_default = async (options, extraWebpackConfig) => {
|
|
|
233
395
|
previewUrl,
|
|
234
396
|
typescriptOptions,
|
|
235
397
|
features
|
|
236
|
-
} = options
|
|
237
|
-
const isProd = configType === "PRODUCTION";
|
|
238
|
-
const workingDir = process.cwd();
|
|
239
|
-
const [
|
|
398
|
+
} = options, isProd = configType === "PRODUCTION", workingDir = process.cwd(), [
|
|
240
399
|
coreOptions,
|
|
241
400
|
frameworkOptions,
|
|
242
401
|
envs,
|
|
@@ -264,84 +423,68 @@ var iframe_rsbuild_config_default = async (options, extraWebpackConfig) => {
|
|
|
264
423
|
options.cache?.get("modulesCount", 1e3),
|
|
265
424
|
options.presets.apply("build"),
|
|
266
425
|
presets.apply("tags", {})
|
|
267
|
-
])
|
|
268
|
-
const stories = (0, import_common2.normalizeStories)(nonNormalizedStories, {
|
|
426
|
+
]), stories = normalizeStories2(nonNormalizedStories, {
|
|
269
427
|
configDir: options.configDir,
|
|
270
428
|
workingDir
|
|
271
|
-
})
|
|
272
|
-
|
|
273
|
-
const tsCheckOptions = typescriptOptions.checkOptions || {};
|
|
274
|
-
const builderOptions = await (0, import_common2.getBuilderOptions)(options);
|
|
275
|
-
const cacheConfig = builderOptions.fsCache ? true : void 0;
|
|
276
|
-
const lazyCompilationConfig = builderOptions.lazyCompilation && !isProd ? {
|
|
277
|
-
lazyCompilation: { entries: false }
|
|
429
|
+
}), shouldCheckTs = typescriptOptions.check && !typescriptOptions.skipCompiler, tsCheckOptions = typescriptOptions.checkOptions || {}, builderOptions = await getBuilderOptions2(options), cacheConfig = builderOptions.fsCache ? !0 : void 0, lazyCompilationConfig = builderOptions.lazyCompilation && !isProd ? {
|
|
430
|
+
lazyCompilation: { entries: !1 }
|
|
278
431
|
} : {};
|
|
279
|
-
if (!template)
|
|
280
|
-
throw new Error(
|
|
432
|
+
if (!template)
|
|
433
|
+
throw new Error(dedent`
|
|
281
434
|
Storybook's Webpack5 builder requires a template to be specified.
|
|
282
435
|
Somehow you've ended up with a falsy value for the template option.
|
|
283
436
|
|
|
284
437
|
Please file an issue at https://github.com/storybookjs/storybook with a reproduction.
|
|
285
438
|
`);
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
}
|
|
291
|
-
const { virtualModules: virtualModuleMapping, entries: dynamicEntries } = await getVirtualModules(options);
|
|
292
|
-
if (!options.cache) {
|
|
439
|
+
let externals = globalsNameReferenceMap;
|
|
440
|
+
build2?.test?.disableBlocks && (externals["@storybook/blocks"] = "__STORYBOOK_BLOCKS_EMPTY_MODULE__");
|
|
441
|
+
let { virtualModules: virtualModuleMapping, entries: dynamicEntries } = await getVirtualModules(options);
|
|
442
|
+
if (!options.cache)
|
|
293
443
|
throw new Error("Cache is required");
|
|
294
|
-
}
|
|
295
|
-
let contentFromConfig = {};
|
|
296
|
-
const { content } = await (0, import_core.loadConfig)({
|
|
444
|
+
let contentFromConfig = {}, { content } = await loadConfig({
|
|
297
445
|
cwd: workingDir,
|
|
298
446
|
path: rsbuildConfigPath
|
|
299
|
-
});
|
|
300
|
-
const { environments, ...withoutEnv } = content;
|
|
447
|
+
}), { environments, ...withoutEnv } = content;
|
|
301
448
|
if (content.environments) {
|
|
302
|
-
|
|
303
|
-
if (envCount === 0)
|
|
449
|
+
let envCount = Object.keys(content.environments).length;
|
|
450
|
+
if (envCount === 0)
|
|
304
451
|
contentFromConfig = withoutEnv;
|
|
305
|
-
|
|
306
|
-
contentFromConfig =
|
|
452
|
+
else if (envCount === 1)
|
|
453
|
+
contentFromConfig = mergeRsbuildConfig(
|
|
307
454
|
withoutEnv,
|
|
308
455
|
content.environments[0]
|
|
309
456
|
);
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
if (typeof userEnv
|
|
457
|
+
else {
|
|
458
|
+
let userEnv = builderOptions.environment;
|
|
459
|
+
if (typeof userEnv != "string")
|
|
313
460
|
throw new Error(
|
|
314
461
|
"You must specify an environment when there are multiple environments in the Rsbuild config."
|
|
315
462
|
);
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
contentFromConfig = (0, import_core.mergeRsbuildConfig)(
|
|
463
|
+
if (Object.keys(content.environments).includes(userEnv))
|
|
464
|
+
contentFromConfig = mergeRsbuildConfig(
|
|
319
465
|
withoutEnv,
|
|
320
466
|
content.environments[userEnv]
|
|
321
467
|
);
|
|
322
|
-
|
|
468
|
+
else
|
|
323
469
|
throw new Error(
|
|
324
470
|
`The specified environment "${userEnv}" is not found in the Rsbuild config.`
|
|
325
471
|
);
|
|
326
|
-
}
|
|
327
472
|
}
|
|
328
|
-
} else
|
|
473
|
+
} else
|
|
329
474
|
contentFromConfig = content;
|
|
330
|
-
|
|
331
|
-
const resourceFilename = isProd ? "static/media/[name].[contenthash:8][ext]" : "static/media/[path][name][ext]";
|
|
332
|
-
const rsbuildConfig = (0, import_core.mergeRsbuildConfig)(contentFromConfig, {
|
|
475
|
+
let resourceFilename = isProd ? "static/media/[name].[contenthash:8][ext]" : "static/media/[path][name][ext]", rsbuildConfig = mergeRsbuildConfig(contentFromConfig, {
|
|
333
476
|
output: {
|
|
334
|
-
cleanDistPath:
|
|
477
|
+
cleanDistPath: !1,
|
|
335
478
|
assetPrefix: "/",
|
|
336
479
|
dataUriLimit: {
|
|
337
480
|
media: 1e4
|
|
338
481
|
},
|
|
339
482
|
sourceMap: {
|
|
340
|
-
js: options.build?.test?.disableSourcemaps ?
|
|
483
|
+
js: options.build?.test?.disableSourcemaps ? !1 : "cheap-module-source-map",
|
|
341
484
|
css: !options.build?.test?.disableSourcemaps
|
|
342
485
|
},
|
|
343
486
|
distPath: {
|
|
344
|
-
root: (
|
|
487
|
+
root: resolve2(process.cwd(), outputDir)
|
|
345
488
|
},
|
|
346
489
|
filename: {
|
|
347
490
|
js: isProd ? "[name].[contenthash:8].iframe.bundle.js" : "[name].iframe.bundle.js",
|
|
@@ -354,7 +497,7 @@ var iframe_rsbuild_config_default = async (options, extraWebpackConfig) => {
|
|
|
354
497
|
server: {
|
|
355
498
|
// Storybook will handle public directory itself, disable Rsbuild's public dir
|
|
356
499
|
// feature to prevent overwriting Storybook's public directory.
|
|
357
|
-
publicDir:
|
|
500
|
+
publicDir: !1
|
|
358
501
|
},
|
|
359
502
|
dev: {
|
|
360
503
|
assetPrefix: "/",
|
|
@@ -367,7 +510,7 @@ var iframe_rsbuild_config_default = async (options, extraWebpackConfig) => {
|
|
|
367
510
|
},
|
|
368
511
|
source: {
|
|
369
512
|
define: {
|
|
370
|
-
...
|
|
513
|
+
...stringifyProcessEnvs(envs),
|
|
371
514
|
NODE_ENV: JSON.stringify(process.env.NODE_ENV)
|
|
372
515
|
}
|
|
373
516
|
},
|
|
@@ -381,102 +524,77 @@ var iframe_rsbuild_config_default = async (options, extraWebpackConfig) => {
|
|
|
381
524
|
buildCache: cacheConfig
|
|
382
525
|
},
|
|
383
526
|
plugins: [
|
|
384
|
-
shouldCheckTs ?
|
|
385
|
-
|
|
386
|
-
collapseWhitespace:
|
|
387
|
-
removeComments:
|
|
388
|
-
removeRedundantAttributes:
|
|
389
|
-
removeScriptTypeAttributes:
|
|
390
|
-
removeStyleLinkTypeAttributes:
|
|
391
|
-
useShortDoctype:
|
|
527
|
+
shouldCheckTs ? pluginTypeCheck(tsCheckOptions) : null,
|
|
528
|
+
pluginHtmlMinifierTerser(() => ({
|
|
529
|
+
collapseWhitespace: !0,
|
|
530
|
+
removeComments: !0,
|
|
531
|
+
removeRedundantAttributes: !0,
|
|
532
|
+
removeScriptTypeAttributes: !1,
|
|
533
|
+
removeStyleLinkTypeAttributes: !0,
|
|
534
|
+
useShortDoctype: !0
|
|
392
535
|
}))
|
|
393
536
|
].filter(Boolean),
|
|
394
537
|
tools: {
|
|
395
538
|
rspack: (config, { addRules, rspack: rspack2, mergeConfig }) => {
|
|
396
|
-
addRules({
|
|
539
|
+
if (addRules({
|
|
397
540
|
test: /\.stories\.([tj])sx?$|(stories|story)\.mdx$/,
|
|
398
541
|
exclude: /node_modules/,
|
|
399
542
|
enforce: "post",
|
|
400
543
|
use: [
|
|
401
544
|
{
|
|
402
|
-
loader:
|
|
545
|
+
loader: __require.resolve(
|
|
546
|
+
"storybook-builder-rsbuild/loaders/export-order-loader"
|
|
547
|
+
)
|
|
403
548
|
}
|
|
404
549
|
]
|
|
405
|
-
})
|
|
406
|
-
config.module ??= {};
|
|
407
|
-
config.module.parser ??= {};
|
|
408
|
-
config.module.parser.javascript ??= {};
|
|
409
|
-
config.module.parser.javascript.unknownContextCritical = false;
|
|
410
|
-
config.resolve ??= {};
|
|
411
|
-
config.resolve.symlinks = !(0, import_common2.isPreservingSymlinks)();
|
|
412
|
-
config.resolve.extensions = Array.from(
|
|
550
|
+
}), config.module ??= {}, config.module.parser ??= {}, config.module.parser.javascript ??= {}, config.module.parser.javascript.unknownContextCritical = !1, config.resolve ??= {}, config.resolve.symlinks = !isPreservingSymlinks(), config.resolve.extensions = Array.from(
|
|
413
551
|
/* @__PURE__ */ new Set([
|
|
414
552
|
...config.resolve.extensions ?? [],
|
|
415
553
|
...builtInResolveExtensions
|
|
416
554
|
])
|
|
417
|
-
)
|
|
418
|
-
config.watchOptions = {
|
|
555
|
+
), config.watchOptions = {
|
|
419
556
|
ignored: /node_modules/
|
|
420
|
-
}
|
|
421
|
-
config.ignoreWarnings = [
|
|
557
|
+
}, config.ignoreWarnings = [
|
|
422
558
|
...config.ignoreWarnings || [],
|
|
423
559
|
/export '\S+' was not found in 'global'/,
|
|
424
560
|
/export '\S+' was not found in '@storybook\/global'/
|
|
425
|
-
]
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
constants: require.resolve("constants-browserify")
|
|
435
|
-
};
|
|
436
|
-
config.optimization ??= {};
|
|
437
|
-
config.optimization.runtimeChunk = true;
|
|
438
|
-
config.optimization.usedExports = options.build?.test?.disableTreeShaking ? false : isProd;
|
|
439
|
-
config.optimization.moduleIds = "named";
|
|
440
|
-
config.module ??= {};
|
|
441
|
-
config.module.parser ??= {};
|
|
442
|
-
config.module.parser.javascript ??= {};
|
|
443
|
-
config.module.parser.javascript.exportsPresence = false;
|
|
444
|
-
if (!rspack2.experiments?.VirtualModulesPlugin) {
|
|
561
|
+
], config.resolve ??= {}, config.resolve.fallback ??= {
|
|
562
|
+
stream: !1,
|
|
563
|
+
path: __require.resolve("path-browserify"),
|
|
564
|
+
assert: __require.resolve("browser-assert"),
|
|
565
|
+
util: __require.resolve("util"),
|
|
566
|
+
url: __require.resolve("url"),
|
|
567
|
+
fs: !1,
|
|
568
|
+
constants: __require.resolve("constants-browserify")
|
|
569
|
+
}, config.optimization ??= {}, config.optimization.runtimeChunk = !0, config.optimization.usedExports = options.build?.test?.disableTreeShaking ? !1 : isProd, config.optimization.moduleIds = "named", config.module ??= {}, config.module.parser ??= {}, config.module.parser.javascript ??= {}, config.module.parser.javascript.exportsPresence = !1, !rspack2.experiments?.VirtualModulesPlugin)
|
|
445
570
|
throw new Error(
|
|
446
571
|
"rspack.experiments.VirtualModulesPlugin requires at least 1.5.0 version of @rsbuild/core, please upgrade or downgrade storybook-rsbuild-builder to lower version."
|
|
447
572
|
);
|
|
448
|
-
|
|
449
|
-
config.plugins ??= [];
|
|
450
|
-
config.plugins.push(
|
|
573
|
+
return config.plugins ??= [], config.plugins.push(
|
|
451
574
|
...[
|
|
452
575
|
Object.keys(virtualModuleMapping).length > 0 ? new rspack2.experiments.VirtualModulesPlugin(
|
|
453
576
|
virtualModuleMapping
|
|
454
577
|
) : null,
|
|
455
578
|
new rspack2.ProvidePlugin({
|
|
456
|
-
process:
|
|
579
|
+
process: __require.resolve("process/browser.js")
|
|
457
580
|
}),
|
|
458
|
-
new
|
|
581
|
+
new CaseSensitivePathsPlugin()
|
|
459
582
|
].filter(Boolean)
|
|
460
|
-
)
|
|
461
|
-
config.experiments ??= {};
|
|
462
|
-
config.experiments.outputModule = false;
|
|
463
|
-
config.externalsType = "var";
|
|
464
|
-
config.output ??= {};
|
|
465
|
-
config.output.module = false;
|
|
466
|
-
config.output.chunkFormat = "array-push";
|
|
467
|
-
config.output.chunkLoading = "jsonp";
|
|
468
|
-
config.experiments = {
|
|
583
|
+
), config.experiments ??= {}, config.experiments.outputModule = !1, config.externalsType = "var", config.output ??= {}, config.output.module = !1, config.output.chunkFormat = "array-push", config.output.chunkLoading = "jsonp", config.experiments = {
|
|
469
584
|
...config.experiments,
|
|
470
585
|
...lazyCompilationConfig
|
|
471
|
-
}
|
|
472
|
-
|
|
586
|
+
}, mergeConfig(
|
|
587
|
+
config,
|
|
588
|
+
extraWebpackConfig || {},
|
|
589
|
+
webpackConfigFromPresets
|
|
590
|
+
);
|
|
473
591
|
},
|
|
474
592
|
htmlPlugin: {
|
|
475
593
|
filename: "iframe.html",
|
|
476
594
|
// FIXME: `none` isn't a known option
|
|
477
595
|
chunksSortMode: "none",
|
|
478
|
-
alwaysWriteToDisk:
|
|
479
|
-
inject:
|
|
596
|
+
alwaysWriteToDisk: !0,
|
|
597
|
+
inject: !1,
|
|
480
598
|
template,
|
|
481
599
|
templateParameters: {
|
|
482
600
|
version: packageJson?.version ?? "0.0.0-storybook-rsbuild-unknown-version",
|
|
@@ -501,74 +619,50 @@ var iframe_rsbuild_config_default = async (options, extraWebpackConfig) => {
|
|
|
501
619
|
}
|
|
502
620
|
}
|
|
503
621
|
});
|
|
504
|
-
rsbuildConfig.source ??= {}
|
|
505
|
-
rsbuildConfig.source.entry = {
|
|
622
|
+
return rsbuildConfig.source ??= {}, rsbuildConfig.source.entry = {
|
|
506
623
|
main: [...entries ?? [], ...dynamicEntries]
|
|
507
|
-
};
|
|
508
|
-
return rsbuildConfig;
|
|
624
|
+
}, rsbuildConfig;
|
|
509
625
|
};
|
|
510
626
|
|
|
511
627
|
// src/react-shims.ts
|
|
512
|
-
|
|
513
|
-
|
|
628
|
+
import { readFile } from "node:fs/promises";
|
|
629
|
+
import { dirname as dirname2, isAbsolute, join as join3 } from "node:path";
|
|
514
630
|
var getIsReactVersion18or19 = async (options) => {
|
|
515
|
-
|
|
631
|
+
let { legacyRootApi } = await options.presets.apply(
|
|
516
632
|
"frameworkOptions"
|
|
517
633
|
) || {};
|
|
518
|
-
if (legacyRootApi)
|
|
519
|
-
return
|
|
520
|
-
|
|
521
|
-
const resolvedReact = await options.presets.apply(
|
|
634
|
+
if (legacyRootApi)
|
|
635
|
+
return !1;
|
|
636
|
+
let resolvedReact = await options.presets.apply(
|
|
522
637
|
"resolvedReact",
|
|
523
638
|
{}
|
|
524
|
-
);
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
}
|
|
530
|
-
const { version } = JSON.parse(
|
|
531
|
-
await (0, import_promises.readFile)((0, import_node_path3.join)(reactDom, "package.json"), "utf-8")
|
|
639
|
+
), reactDom = "";
|
|
640
|
+
if (reactDom = resolvedReact.reactDom || dirname2(__require.resolve("react-dom/package.json")), !isAbsolute(reactDom))
|
|
641
|
+
return !1;
|
|
642
|
+
let { version } = JSON.parse(
|
|
643
|
+
await readFile(join3(reactDom, "package.json"), "utf-8")
|
|
532
644
|
);
|
|
533
645
|
return version.startsWith("18") || version.startsWith("19") || version.startsWith("0.0.0");
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
return {};
|
|
539
|
-
}
|
|
540
|
-
return {
|
|
541
|
-
resolve: {
|
|
542
|
-
alias: {
|
|
543
|
-
"@storybook/react-dom-shim": "@storybook/react-dom-shim/dist/react-16"
|
|
544
|
-
}
|
|
646
|
+
}, applyReactShims = async (config, options) => await getIsReactVersion18or19(options) ? {} : {
|
|
647
|
+
resolve: {
|
|
648
|
+
alias: {
|
|
649
|
+
"@storybook/react-dom-shim": "@storybook/react-dom-shim/react-16"
|
|
545
650
|
}
|
|
546
|
-
}
|
|
651
|
+
}
|
|
547
652
|
};
|
|
548
653
|
|
|
549
654
|
// src/index.ts
|
|
550
|
-
var corePath = (0,
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
get: async (options) => {
|
|
554
|
-
const rsbuildInstance = await options.presets.apply("rsbuildInstance") || rsbuildReal;
|
|
555
|
-
return rsbuildInstance;
|
|
556
|
-
}
|
|
557
|
-
};
|
|
558
|
-
var isObject = (val) => val != null && typeof val === "object" && Array.isArray(val) === false;
|
|
655
|
+
var corePath = dirname3(__require.resolve("storybook/package.json")), printDuration = (startTime) => (0, import_pretty_hrtime.default)(process.hrtime(startTime)).replace(" ms", " milliseconds").replace(" s", " seconds").replace(" m", " minutes"), executor = {
|
|
656
|
+
get: async (options) => await options.presets.apply("rsbuildInstance") || rsbuildReal
|
|
657
|
+
}, isObject = (val) => val != null && typeof val == "object" && Array.isArray(val) === !1;
|
|
559
658
|
function nonNullables(value) {
|
|
560
659
|
return value !== void 0;
|
|
561
660
|
}
|
|
562
661
|
var rsbuild = async (_, options) => {
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
const name = isObject(preset) ? preset.name : preset;
|
|
568
|
-
return (0, import_common3.resolveAddonName)(options.configDir, name, addonOptions);
|
|
569
|
-
}).filter(nonNullables);
|
|
570
|
-
const { apply } = await (0, import_common3.getPresets)(resolvedWebpackAddons, options);
|
|
571
|
-
const webpackAddonsConfig = await apply(
|
|
662
|
+
let { presets } = options, resolvedWebpackAddons = (await presets.apply("webpackAddons") ?? []).map((preset) => {
|
|
663
|
+
let addonOptions = isObject(preset) && preset.options || void 0, name = isObject(preset) ? preset.name : preset;
|
|
664
|
+
return resolveAddonName(options.configDir, name, addonOptions);
|
|
665
|
+
}).filter(nonNullables), { apply } = await getPresets(resolvedWebpackAddons, options), webpackAddonsConfig = await apply(
|
|
572
666
|
"webpackFinal",
|
|
573
667
|
// TODO: using empty webpack config as base for now. It's better to using the composed rspack
|
|
574
668
|
// config in `iframe-rsbuild.config.ts` as base config. But when `tools.rspack` is an async function,
|
|
@@ -589,31 +683,23 @@ var rsbuild = async (_, options) => {
|
|
|
589
683
|
entry: {}
|
|
590
684
|
},
|
|
591
685
|
options
|
|
592
|
-
);
|
|
593
|
-
|
|
594
|
-
const shimsConfig = await applyReactShims(intrinsicRsbuildConfig, options);
|
|
595
|
-
intrinsicRsbuildConfig = rsbuildReal.mergeRsbuildConfig(
|
|
686
|
+
), intrinsicRsbuildConfig = await iframe_rsbuild_config_default(options, webpackAddonsConfig), shimsConfig = await applyReactShims(intrinsicRsbuildConfig, options);
|
|
687
|
+
return intrinsicRsbuildConfig = rsbuildReal.mergeRsbuildConfig(
|
|
596
688
|
intrinsicRsbuildConfig,
|
|
597
689
|
shimsConfig
|
|
598
|
-
)
|
|
599
|
-
const finalConfig = await presets.apply(
|
|
690
|
+
), await presets.apply(
|
|
600
691
|
"rsbuildFinal",
|
|
601
692
|
intrinsicRsbuildConfig,
|
|
602
693
|
options
|
|
603
694
|
);
|
|
604
|
-
|
|
605
|
-
};
|
|
606
|
-
var getConfig = async (options) => {
|
|
607
|
-
const { presets } = options;
|
|
608
|
-
const typescriptOptions = await presets.apply("typescript", {}, options);
|
|
609
|
-
const frameworkOptions = await presets.apply("frameworkOptions");
|
|
695
|
+
}, getConfig = async (options) => {
|
|
696
|
+
let { presets } = options, typescriptOptions = await presets.apply("typescript", {}, options), frameworkOptions = await presets.apply("frameworkOptions");
|
|
610
697
|
return rsbuild({}, {
|
|
611
698
|
...options,
|
|
612
699
|
typescriptOptions,
|
|
613
700
|
frameworkOptions
|
|
614
701
|
});
|
|
615
|
-
};
|
|
616
|
-
var server;
|
|
702
|
+
}, server;
|
|
617
703
|
async function bail() {
|
|
618
704
|
return server?.close();
|
|
619
705
|
}
|
|
@@ -624,9 +710,7 @@ var start = async ({
|
|
|
624
710
|
server: storybookServer,
|
|
625
711
|
channel
|
|
626
712
|
}) => {
|
|
627
|
-
|
|
628
|
-
const config = await getConfig(options);
|
|
629
|
-
const rsbuildBuild = await createRsbuild({
|
|
713
|
+
let { createRsbuild } = await executor.get(options), config = await getConfig(options), rsbuildBuild = await createRsbuild({
|
|
630
714
|
cwd: process.cwd(),
|
|
631
715
|
rsbuildConfig: {
|
|
632
716
|
...config,
|
|
@@ -634,90 +718,59 @@ var start = async ({
|
|
|
634
718
|
...config.server,
|
|
635
719
|
port: await getRandomPort(options.host),
|
|
636
720
|
host: options.host,
|
|
637
|
-
htmlFallback:
|
|
638
|
-
printUrls:
|
|
721
|
+
htmlFallback: !1,
|
|
722
|
+
printUrls: !1
|
|
639
723
|
}
|
|
640
724
|
}
|
|
641
|
-
})
|
|
642
|
-
const rsbuildServer = await rsbuildBuild.createDevServer();
|
|
643
|
-
const waitFirstCompileDone = new Promise((resolve3) => {
|
|
725
|
+
}), rsbuildServer = await rsbuildBuild.createDevServer(), waitFirstCompileDone = new Promise((resolve3) => {
|
|
644
726
|
rsbuildBuild.onDevCompileDone(({ stats: stats2, isFirstCompile }) => {
|
|
645
|
-
|
|
646
|
-
return;
|
|
647
|
-
}
|
|
648
|
-
resolve3(stats2);
|
|
727
|
+
isFirstCompile && resolve3(stats2);
|
|
649
728
|
});
|
|
650
729
|
});
|
|
651
|
-
server = rsbuildServer
|
|
652
|
-
|
|
653
|
-
throw new import_server_errors.WebpackInvocationError({
|
|
730
|
+
if (server = rsbuildServer, !rsbuildBuild)
|
|
731
|
+
throw new WebpackInvocationError({
|
|
654
732
|
// eslint-disable-next-line local-rules/no-uncategorized-errors
|
|
655
733
|
error: new Error("Missing Rsbuild build instance at runtime!")
|
|
656
734
|
});
|
|
657
|
-
|
|
658
|
-
const previewResolvedDir = (0, import_node_path4.join)(corePath, "dist/preview");
|
|
659
|
-
const previewDirOrigin = previewResolvedDir;
|
|
735
|
+
let previewDirOrigin = join4(corePath, "dist/preview");
|
|
660
736
|
router.use(
|
|
661
737
|
"/sb-preview",
|
|
662
|
-
(
|
|
663
|
-
);
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
const stats = await waitFirstCompileDone;
|
|
667
|
-
await server.afterListen();
|
|
668
|
-
return {
|
|
738
|
+
sirv(previewDirOrigin, { maxAge: 3e5, dev: !0, immutable: !0 })
|
|
739
|
+
), router.use(rsbuildServer.middlewares), rsbuildServer.connectWebSocket({ server: storybookServer });
|
|
740
|
+
let stats = await waitFirstCompileDone;
|
|
741
|
+
return await server.afterListen(), {
|
|
669
742
|
bail,
|
|
670
743
|
stats,
|
|
671
744
|
totalTime: process.hrtime(startTime)
|
|
672
745
|
};
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
const { createRsbuild } = await executor.get(options);
|
|
676
|
-
const config = await getConfig(options);
|
|
677
|
-
const rsbuildBuild = await createRsbuild({
|
|
746
|
+
}, build = async ({ options }) => {
|
|
747
|
+
let { createRsbuild } = await executor.get(options), config = await getConfig(options), rsbuildBuild = await createRsbuild({
|
|
678
748
|
cwd: process.cwd(),
|
|
679
749
|
rsbuildConfig: config
|
|
680
|
-
});
|
|
681
|
-
const previewResolvedDir = (0, import_node_path4.join)(corePath, "dist/preview");
|
|
682
|
-
const previewDirOrigin = previewResolvedDir;
|
|
683
|
-
const previewDirTarget = (0, import_node_path4.join)(options.outputDir || "", "sb-preview");
|
|
684
|
-
let stats;
|
|
750
|
+
}), previewDirOrigin = join4(corePath, "dist/preview"), previewDirTarget = join4(options.outputDir || "", "sb-preview"), stats;
|
|
685
751
|
rsbuildBuild.onAfterBuild((params) => {
|
|
686
752
|
stats = params.stats;
|
|
687
753
|
});
|
|
688
|
-
|
|
754
|
+
let previewFiles = fs.copy(previewDirOrigin, previewDirTarget, {
|
|
689
755
|
filter: (src) => {
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
return ext === ".js";
|
|
693
|
-
}
|
|
694
|
-
return true;
|
|
756
|
+
let { ext } = parse(src);
|
|
757
|
+
return ext ? ext === ".js" : !0;
|
|
695
758
|
}
|
|
696
|
-
});
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
});
|
|
700
|
-
const [{ close }] = await Promise.all([rsbuildBuild.build(), previewFiles]);
|
|
701
|
-
await close();
|
|
702
|
-
return stats;
|
|
703
|
-
};
|
|
704
|
-
var corePresets = [(0, import_node_path4.join)(__dirname, "./preview-preset.js")];
|
|
705
|
-
var previewMainTemplate = () => require.resolve("storybook-builder-rsbuild/templates/preview.ejs");
|
|
759
|
+
}), [{ close }] = await Promise.all([rsbuildBuild.build(), previewFiles]);
|
|
760
|
+
return await close(), stats;
|
|
761
|
+
}, corePresets = [join4(__dirname, "./preview-preset.js")], previewMainTemplate = () => __require.resolve("storybook-builder-rsbuild/templates/preview.ejs");
|
|
706
762
|
function getRandomPort(host) {
|
|
707
763
|
return new Promise((resolve3, reject) => {
|
|
708
|
-
|
|
709
|
-
server2.unref()
|
|
710
|
-
|
|
711
|
-
server2.listen({ port: 0, host }, () => {
|
|
712
|
-
const { port } = server2.address();
|
|
764
|
+
let server2 = createServer();
|
|
765
|
+
server2.unref(), server2.on("error", reject), server2.listen({ port: 0, host }, () => {
|
|
766
|
+
let { port } = server2.address();
|
|
713
767
|
server2.close(() => {
|
|
714
768
|
resolve3(port);
|
|
715
769
|
});
|
|
716
770
|
});
|
|
717
771
|
});
|
|
718
772
|
}
|
|
719
|
-
|
|
720
|
-
0 && (module.exports = {
|
|
773
|
+
export {
|
|
721
774
|
bail,
|
|
722
775
|
build,
|
|
723
776
|
corePresets,
|
|
@@ -727,4 +780,4 @@ function getRandomPort(host) {
|
|
|
727
780
|
previewMainTemplate,
|
|
728
781
|
printDuration,
|
|
729
782
|
start
|
|
730
|
-
}
|
|
783
|
+
};
|