storybook-react-rsbuild 2.1.6 → 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.
@@ -0,0 +1,21 @@
1
+ import CJS_COMPAT_NODE_URL_456fc18c5bc9e809 from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_456fc18c5bc9e809 from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_456fc18c5bc9e809 from "node:module";
4
+
5
+ var __filename = CJS_COMPAT_NODE_URL_456fc18c5bc9e809.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_456fc18c5bc9e809.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_456fc18c5bc9e809.createRequire(import.meta.url);
8
+
9
+ // ------------------------------------------------------------
10
+ // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
+ // ------------------------------------------------------------
12
+ var __require = /* @__PURE__ */ ((x) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(x, {
13
+ get: (a, b) => (typeof require < "u" ? require : a)[b]
14
+ }) : x)(function(x) {
15
+ if (typeof require < "u") return require.apply(this, arguments);
16
+ throw Error('Dynamic require of "' + x + '" is not supported');
17
+ });
18
+
19
+ export {
20
+ __require
21
+ };
@@ -0,0 +1,162 @@
1
+ import CJS_COMPAT_NODE_URL_456fc18c5bc9e809 from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_456fc18c5bc9e809 from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_456fc18c5bc9e809 from "node:module";
4
+
5
+ var __filename = CJS_COMPAT_NODE_URL_456fc18c5bc9e809.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_456fc18c5bc9e809.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_456fc18c5bc9e809.createRequire(import.meta.url);
8
+
9
+ // ------------------------------------------------------------
10
+ // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
+ // ------------------------------------------------------------
12
+ import "./chunk-736S2ISL.js";
13
+
14
+ // src/plugins/react-docgen-typescript/utils/generate.ts
15
+ import MagicString from "magic-string";
16
+ import ts from "typescript";
17
+ function createLiteral(value) {
18
+ switch (typeof value) {
19
+ case "string":
20
+ return ts.factory.createStringLiteral(value);
21
+ case "number":
22
+ return ts.factory.createNumericLiteral(value);
23
+ case "boolean":
24
+ return value ? ts.factory.createTrue() : ts.factory.createFalse();
25
+ }
26
+ }
27
+ function insertTsIgnoreBeforeStatement(statement) {
28
+ return ts.setSyntheticLeadingComments(statement, [
29
+ {
30
+ text: " @ts-ignore",
31
+ // Leading space is important here
32
+ kind: ts.SyntaxKind.SingleLineCommentTrivia,
33
+ pos: -1,
34
+ end: -1
35
+ }
36
+ ]), statement;
37
+ }
38
+ function setDisplayName(d) {
39
+ return insertTsIgnoreBeforeStatement(
40
+ ts.factory.createExpressionStatement(
41
+ ts.factory.createBinaryExpression(
42
+ ts.factory.createPropertyAccessExpression(
43
+ ts.factory.createIdentifier(d.displayName),
44
+ ts.factory.createIdentifier("displayName")
45
+ ),
46
+ ts.SyntaxKind.EqualsToken,
47
+ ts.factory.createStringLiteral(d.displayName)
48
+ )
49
+ )
50
+ );
51
+ }
52
+ function createPropDefinition(propName, prop, options) {
53
+ let setDefaultValue = (defaultValue) => ts.factory.createPropertyAssignment(
54
+ ts.factory.createStringLiteral("defaultValue"),
55
+ // Use a more extensive check on defaultValue. Sometimes the parser
56
+ // returns an empty object.
57
+ defaultValue?.value !== void 0 && (typeof defaultValue.value == "string" || typeof defaultValue.value == "number" || typeof defaultValue.value == "boolean") ? ts.factory.createObjectLiteralExpression([
58
+ ts.factory.createPropertyAssignment(
59
+ ts.factory.createIdentifier("value"),
60
+ createLiteral(defaultValue.value)
61
+ )
62
+ ]) : ts.factory.createNull()
63
+ ), setStringLiteralField = (fieldName, fieldValue) => ts.factory.createPropertyAssignment(
64
+ ts.factory.createStringLiteral(fieldName),
65
+ ts.factory.createStringLiteral(fieldValue)
66
+ ), setDescription = (description) => setStringLiteralField("description", description), setName = (name) => setStringLiteralField("name", name), setRequired = (required) => ts.factory.createPropertyAssignment(
67
+ ts.factory.createStringLiteral("required"),
68
+ required ? ts.factory.createTrue() : ts.factory.createFalse()
69
+ ), setValue = (typeValue) => Array.isArray(typeValue) && typeValue.every((value) => typeof value.value == "string") ? ts.factory.createPropertyAssignment(
70
+ ts.factory.createStringLiteral("value"),
71
+ ts.factory.createArrayLiteralExpression(
72
+ typeValue.map(
73
+ (value) => ts.factory.createObjectLiteralExpression([
74
+ setStringLiteralField("value", value.value)
75
+ ])
76
+ )
77
+ )
78
+ ) : void 0, setType = (typeName, typeValue) => {
79
+ let objectFields = [setStringLiteralField("name", typeName)], valueField = setValue(typeValue);
80
+ return valueField && objectFields.push(valueField), ts.factory.createPropertyAssignment(
81
+ ts.factory.createStringLiteral(options.typePropName),
82
+ ts.factory.createObjectLiteralExpression(objectFields)
83
+ );
84
+ };
85
+ return ts.factory.createPropertyAssignment(
86
+ ts.factory.createStringLiteral(propName),
87
+ ts.factory.createObjectLiteralExpression([
88
+ setDefaultValue(prop.defaultValue),
89
+ setDescription(prop.description),
90
+ setName(prop.name),
91
+ setRequired(prop.required),
92
+ setType(prop.type.name, prop.type.value)
93
+ ])
94
+ );
95
+ }
96
+ function setComponentDocGen(d, options) {
97
+ return insertTsIgnoreBeforeStatement(
98
+ ts.factory.createExpressionStatement(
99
+ ts.factory.createBinaryExpression(
100
+ // SimpleComponent.__docgenInfo
101
+ ts.factory.createPropertyAccessExpression(
102
+ ts.factory.createIdentifier(d.displayName),
103
+ ts.factory.createIdentifier("__docgenInfo")
104
+ ),
105
+ ts.SyntaxKind.EqualsToken,
106
+ ts.factory.createObjectLiteralExpression([
107
+ // SimpleComponent.__docgenInfo.description
108
+ ts.factory.createPropertyAssignment(
109
+ ts.factory.createStringLiteral("description"),
110
+ ts.factory.createStringLiteral(d.description)
111
+ ),
112
+ // SimpleComponent.__docgenInfo.displayName
113
+ ts.factory.createPropertyAssignment(
114
+ ts.factory.createStringLiteral("displayName"),
115
+ ts.factory.createStringLiteral(d.displayName)
116
+ ),
117
+ // SimpleComponent.__docgenInfo.props
118
+ ts.factory.createPropertyAssignment(
119
+ ts.factory.createStringLiteral("props"),
120
+ ts.factory.createObjectLiteralExpression(
121
+ Object.entries(d.props).map(
122
+ ([propName, prop]) => createPropDefinition(propName, prop, options)
123
+ )
124
+ )
125
+ )
126
+ ])
127
+ )
128
+ )
129
+ );
130
+ }
131
+ function generateDocgenCodeBlock(options) {
132
+ let sourceFile = ts.createSourceFile(
133
+ options.filename,
134
+ options.source,
135
+ ts.ScriptTarget.ESNext
136
+ ), wrapInTryStatement = (statements) => ts.factory.createTryStatement(
137
+ ts.factory.createBlock(statements, !0),
138
+ ts.factory.createCatchClause(
139
+ ts.factory.createVariableDeclaration(
140
+ ts.factory.createIdentifier("__react_docgen_typescript_loader_error")
141
+ ),
142
+ ts.factory.createBlock([])
143
+ ),
144
+ void 0
145
+ ), codeBlocks = options.componentDocs.map(
146
+ (d) => wrapInTryStatement(
147
+ [
148
+ options.setDisplayName ? setDisplayName(d) : null,
149
+ setComponentDocGen(d, options)
150
+ ].filter((s2) => s2 !== null)
151
+ )
152
+ ), printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed }), printNode = (sourceNode) => printer.printNode(ts.EmitHint.Unspecified, sourceNode, sourceFile), s = new MagicString(options.source);
153
+ for (let node of codeBlocks)
154
+ s.append(printNode(node));
155
+ return {
156
+ code: s.toString(),
157
+ map: s.generateMap()
158
+ };
159
+ }
160
+ export {
161
+ generateDocgenCodeBlock
162
+ };
@@ -0,0 +1,24 @@
1
+ import CJS_COMPAT_NODE_URL_456fc18c5bc9e809 from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_456fc18c5bc9e809 from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_456fc18c5bc9e809 from "node:module";
4
+
5
+ var __filename = CJS_COMPAT_NODE_URL_456fc18c5bc9e809.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_456fc18c5bc9e809.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_456fc18c5bc9e809.createRequire(import.meta.url);
8
+
9
+ // ------------------------------------------------------------
10
+ // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
+ // ------------------------------------------------------------
12
+ import "./chunk-736S2ISL.js";
13
+
14
+ // src/plugins/react-docgen-typescript/utils/options.ts
15
+ function getGenerateOptions(options) {
16
+ let { setDisplayName = !0, typePropName = "type" } = options;
17
+ return {
18
+ setDisplayName,
19
+ typePropName
20
+ };
21
+ }
22
+ export {
23
+ getGenerateOptions
24
+ };
@@ -0,0 +1,114 @@
1
+ import CJS_COMPAT_NODE_URL_456fc18c5bc9e809 from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_456fc18c5bc9e809 from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_456fc18c5bc9e809 from "node:module";
4
+
5
+ var __filename = CJS_COMPAT_NODE_URL_456fc18c5bc9e809.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_456fc18c5bc9e809.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_456fc18c5bc9e809.createRequire(import.meta.url);
8
+
9
+ // ------------------------------------------------------------
10
+ // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
+ // ------------------------------------------------------------
12
+ import "./chunk-736S2ISL.js";
13
+
14
+ // src/plugins/react-docgen-typescript/index.ts
15
+ import { createFilter } from "@rollup/pluginutils";
16
+
17
+ // src/plugins/react-docgen-typescript/utils/filter.ts
18
+ var defaultPropFilter = (prop) => !prop.parent?.fileName.includes("node_modules");
19
+
20
+ // src/plugins/react-docgen-typescript/index.ts
21
+ var getDocgen = async (config) => {
22
+ let docGen = await import("react-docgen-typescript"), {
23
+ tsconfigPath,
24
+ compilerOptions,
25
+ propFilter = defaultPropFilter,
26
+ setDisplayName,
27
+ typePropName,
28
+ ...rest
29
+ } = config, docgenOptions = {
30
+ propFilter,
31
+ ...rest
32
+ };
33
+ return docGen.withCompilerOptions(
34
+ // Compiler Options are passed in to the custom program.
35
+ {},
36
+ docgenOptions
37
+ );
38
+ }, startWatch = async (config, onProgramCreatedOrUpdated) => {
39
+ let { default: ts } = await import("typescript"), { getTSConfigFile } = await import("./typescript-Q2KR3T37.js"), compilerOptions = {
40
+ jsx: ts.JsxEmit.React,
41
+ module: ts.ModuleKind.CommonJS,
42
+ target: ts.ScriptTarget.Latest
43
+ }, tsconfigPath = config.tsconfigPath ?? "./tsconfig.json";
44
+ if (config.compilerOptions)
45
+ compilerOptions = {
46
+ ...compilerOptions,
47
+ ...config.compilerOptions
48
+ };
49
+ else {
50
+ let { options: tsOptions } = getTSConfigFile(tsconfigPath);
51
+ compilerOptions = { ...compilerOptions, ...tsOptions };
52
+ }
53
+ let host = ts.createWatchCompilerHost(
54
+ tsconfigPath,
55
+ compilerOptions,
56
+ ts.sys,
57
+ ts.createSemanticDiagnosticsBuilderProgram,
58
+ void 0,
59
+ () => {
60
+ }
61
+ );
62
+ return host.afterProgramCreate = (program) => {
63
+ onProgramCreatedOrUpdated(program.getProgram());
64
+ }, new Promise((resolve) => {
65
+ let watch = ts.createWatchProgram(host);
66
+ resolve([watch.getProgram().getProgram(), watch.close]);
67
+ });
68
+ }, react_docgen_typescript_default = (config = {}) => {
69
+ let tsProgram, docGenParser, generateDocgenCodeBlock, generateOptions, filter, moduleInvalidationQueue = /* @__PURE__ */ new Map(), closeWatch;
70
+ return {
71
+ name: "rsbuild-plugin-react-docgen-typescript",
72
+ setup(api) {
73
+ api.modifyRsbuildConfig(async () => {
74
+ let { getGenerateOptions } = await import("./options-IABV5J64.js");
75
+ generateDocgenCodeBlock = (await import("./generate-ZW2DFGJB.js")).generateDocgenCodeBlock, docGenParser = await getDocgen(config), generateOptions = getGenerateOptions(config), [tsProgram, closeWatch] = await startWatch(config, (program) => {
76
+ tsProgram = program;
77
+ for (let [
78
+ filepath,
79
+ invalidateModule
80
+ ] of moduleInvalidationQueue.entries())
81
+ invalidateModule(), moduleInvalidationQueue.delete(filepath);
82
+ }), filter = createFilter(
83
+ config.include ?? ["**/**.tsx"],
84
+ config.exclude ?? ["**/**.stories.tsx"]
85
+ );
86
+ }), api.transform(
87
+ {
88
+ test: (id) => filter(id)
89
+ },
90
+ async ({ code: src, resource: id }) => {
91
+ try {
92
+ let componentDocs = docGenParser.parseWithProgramProvider(
93
+ id,
94
+ () => tsProgram
95
+ );
96
+ return componentDocs.length ? generateDocgenCodeBlock({
97
+ filename: id,
98
+ source: src,
99
+ componentDocs,
100
+ ...generateOptions
101
+ }) : { code: src };
102
+ } catch {
103
+ return src;
104
+ }
105
+ }
106
+ ), api.onCloseBuild(() => {
107
+ closeWatch();
108
+ });
109
+ }
110
+ };
111
+ };
112
+ export {
113
+ react_docgen_typescript_default as default
114
+ };
@@ -0,0 +1,33 @@
1
+ import CJS_COMPAT_NODE_URL_456fc18c5bc9e809 from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_456fc18c5bc9e809 from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_456fc18c5bc9e809 from "node:module";
4
+
5
+ var __filename = CJS_COMPAT_NODE_URL_456fc18c5bc9e809.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_456fc18c5bc9e809.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_456fc18c5bc9e809.createRequire(import.meta.url);
8
+
9
+ // ------------------------------------------------------------
10
+ // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
+ // ------------------------------------------------------------
12
+ import "./chunk-736S2ISL.js";
13
+
14
+ // src/plugins/react-docgen-typescript/utils/typescript.ts
15
+ import { dirname } from "node:path";
16
+ import ts from "typescript";
17
+ function getTSConfigFile(tsconfigPath) {
18
+ try {
19
+ let basePath = dirname(tsconfigPath), configFile = ts.readConfigFile(tsconfigPath, ts.sys.readFile);
20
+ return ts.parseJsonConfigFileContent(
21
+ configFile.config,
22
+ ts.sys,
23
+ basePath,
24
+ {},
25
+ tsconfigPath
26
+ );
27
+ } catch {
28
+ return {};
29
+ }
30
+ }
31
+ export {
32
+ getTSConfigFile
33
+ };
package/dist/index.d.ts CHANGED
@@ -1,54 +1,3 @@
1
- export * from '@storybook/react';
2
- export { __definePreview as definePreview } from '@storybook/react';
3
- import { PluginOptions } from '@storybook/react-docgen-typescript-plugin';
4
- import { BuilderOptions, StorybookConfigRsbuild, TypescriptOptions as TypescriptOptions$1 } from 'storybook-builder-rsbuild';
5
- import { StorybookConfig as StorybookConfig$1, TypescriptOptions } from 'storybook/internal/types';
6
-
7
- type FrameworkName = 'storybook-react-rsbuild';
8
- type BuilderName = 'storybook-builder-rsbuild';
9
- type FrameworkOptions = {
10
- builder?: BuilderOptions;
11
- strictMode?: boolean;
12
- /**
13
- * Use React's legacy root API to mount components
14
- * @description
15
- * React has introduced a new root API with React 18.x to enable a whole set of new features (e.g. concurrent features)
16
- * If this flag is true, the legacy Root API is used to mount components to make it easier to migrate step by step to React 18.
17
- * @default false
18
- */
19
- legacyRootApi?: boolean;
20
- };
21
- type TypescriptOptionsReact = {
22
- /**
23
- * Sets the type of Docgen when working with React and TypeScript
24
- *
25
- * @default `'react-docgen'`
26
- */
27
- reactDocgen: 'react-docgen-typescript' | 'react-docgen' | false;
28
- /**
29
- * Configures `react-docgen-typescript-plugin`
30
- *
31
- * @default
32
- * @see https://github.com/storybookjs/storybook/blob/next/code/builders/builder-webpack5/src/config/defaults.js#L4-L6
33
- */
34
- reactDocgenTypescriptOptions: PluginOptions;
35
- };
36
- type StorybookConfigFramework = {
37
- framework: FrameworkName | {
38
- name: FrameworkName;
39
- options: FrameworkOptions;
40
- };
41
- core?: StorybookConfig$1['core'] & {
42
- builder?: BuilderName | {
43
- name: BuilderName;
44
- options: BuilderOptions;
45
- };
46
- };
47
- typescript?: Partial<TypescriptOptions & TypescriptOptions$1 & TypescriptOptionsReact>;
48
- };
49
- /**
50
- * The interface for Storybook configuration in `main.ts` files.
51
- */
52
- type StorybookConfig = Omit<StorybookConfig$1, keyof StorybookConfigRsbuild | keyof StorybookConfigFramework> & StorybookConfigRsbuild & StorybookConfigFramework;
53
-
54
- export { FrameworkOptions, StorybookConfig };
1
+ // auto generated file from file:///Users/bytedance/Projects/storybook-rsbuild/scripts/build/utils/generate-type-mappers.ts, do not edit
2
+ export * from '../src/index.ts';
3
+ export type * from '../src/index.ts';
package/dist/index.js CHANGED
@@ -1,33 +1,6 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
-
21
1
  // src/index.ts
22
- var src_exports = {};
23
- __export(src_exports, {
24
- definePreview: () => import_react.__definePreview
25
- });
26
- module.exports = __toCommonJS(src_exports);
27
- __reExport(src_exports, require("@storybook/react"), module.exports);
28
- var import_react = require("@storybook/react");
29
- // Annotate the CommonJS export names for ESM import in node:
30
- 0 && (module.exports = {
31
- definePreview,
32
- ...require("@storybook/react")
33
- });
2
+ export * from "@storybook/react";
3
+ import { __definePreview } from "@storybook/react";
4
+ export {
5
+ __definePreview as definePreview
6
+ };
@@ -1,10 +1,3 @@
1
- import * as react_docgen from 'react-docgen';
2
- import * as TsconfigPaths from 'tsconfig-paths';
3
- import { LoaderContext } from 'webpack';
4
-
5
- declare function reactDocgenLoader(this: LoaderContext<{
6
- debug: boolean;
7
- }>, source: string, map: any): Promise<void>;
8
- declare function getReactDocgenImporter(matchingPath: TsconfigPaths.MatchPath | undefined): react_docgen.Importer;
9
-
10
- export { reactDocgenLoader as default, getReactDocgenImporter };
1
+ // auto generated file from file:///Users/bytedance/Projects/storybook-rsbuild/scripts/build/utils/generate-type-mappers.ts, do not edit
2
+ export * from '../../src/loaders/react-docgen-loader.ts';
3
+ export type * from '../../src/loaders/react-docgen-loader.ts';