storybook-react-rsbuild 0.0.2 → 0.0.4

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.
@@ -1,4 +1,4 @@
1
- import { BuilderOptions as BuilderOptions$1, StorybookConfigRsbuild } from 'storybook-builder-rsbuild';
1
+ import { BuilderOptions as BuilderOptions$1, StorybookConfigRsbuild, TypescriptOptions as TypescriptOptions$1 } from 'storybook-builder-rsbuild';
2
2
  import { FileSystemCache } from 'file-system-cache';
3
3
  import { Server } from 'http';
4
4
  import { PluginOptions } from '@storybook/react-docgen-typescript-plugin';
@@ -801,8 +801,6 @@ type BaseIndexInput = {
801
801
  metaId?: MetaId;
802
802
  /** Tags for filtering entries in Storybook and its tools. */
803
803
  tags?: Tag$1[];
804
- /** Tags from the meta for filtering entries in Storybook and its tools. */
805
- metaTags?: Tag$1[];
806
804
  /**
807
805
  * The id of the entry, auto-generated from {@link title}/{@link metaId} and {@link exportName} if unspecified.
808
806
  * If specified, the story in the CSF file _must_ have a matching id set at `parameters.__id`, to be correctly matched.
@@ -871,7 +869,7 @@ interface DirectoryMapping {
871
869
  to: string;
872
870
  }
873
871
  interface Presets {
874
- apply(extension: 'typescript', config: TypescriptOptions$1, args?: Options): Promise<TypescriptOptions$1>;
872
+ apply(extension: 'typescript', config: TypescriptOptions, args?: Options): Promise<TypescriptOptions>;
875
873
  apply(extension: 'framework', config?: {}, args?: any): Promise<Preset>;
876
874
  apply(extension: 'babel', config?: {}, args?: any): Promise<any>;
877
875
  apply(extension: 'swc', config?: {}, args?: any): Promise<any>;
@@ -958,7 +956,7 @@ type Options = LoadOptions & StorybookConfigOptions & CLIOptions & BuilderOption
958
956
  /**
959
957
  * Options for TypeScript usage within Storybook.
960
958
  */
961
- interface TypescriptOptions$1 {
959
+ interface TypescriptOptions {
962
960
  /**
963
961
  * Enables type checking within Storybook.
964
962
  *
@@ -997,6 +995,8 @@ type DocsOptions = {
997
995
  * Should we generate a docs entry per CSF file?
998
996
  * Set to 'tag' (the default) to generate an entry for every CSF file with the
999
997
  * 'autodocs' tag.
998
+ *
999
+ * @deprecated Use `tags: ['autodocs']` in `.storybook/preview.js` instead
1000
1000
  */
1001
1001
  autodocs?: boolean | 'tag';
1002
1002
  /**
@@ -1084,7 +1084,7 @@ interface StorybookConfigRaw {
1084
1084
  build?: TestBuildConfig;
1085
1085
  stories: StoriesEntry[];
1086
1086
  framework?: Preset;
1087
- typescript?: Partial<TypescriptOptions$1>;
1087
+ typescript?: Partial<TypescriptOptions>;
1088
1088
  refs?: CoreCommon_StorybookRefs;
1089
1089
  babel?: any;
1090
1090
  swc?: any;
@@ -1212,19 +1212,7 @@ type FrameworkOptions = {
1212
1212
  */
1213
1213
  legacyRootApi?: boolean;
1214
1214
  };
1215
- type StorybookConfigFramework = {
1216
- framework: FrameworkName | {
1217
- name: FrameworkName;
1218
- options: FrameworkOptions;
1219
- };
1220
- core?: StorybookConfig$1['core'] & {
1221
- builder?: BuilderName | {
1222
- name: BuilderName;
1223
- options: BuilderOptions$1;
1224
- };
1225
- };
1226
- };
1227
- type TypescriptOptions = StorybookConfig$1['typescript'] & {
1215
+ type TypescriptOptionsReact = {
1228
1216
  /**
1229
1217
  * Sets the type of Docgen when working with React and TypeScript
1230
1218
  *
@@ -1239,11 +1227,22 @@ type TypescriptOptions = StorybookConfig$1['typescript'] & {
1239
1227
  */
1240
1228
  reactDocgenTypescriptOptions: PluginOptions;
1241
1229
  };
1230
+ type StorybookConfigFramework = {
1231
+ framework: FrameworkName | {
1232
+ name: FrameworkName;
1233
+ options: FrameworkOptions;
1234
+ };
1235
+ core?: StorybookConfig$1['core'] & {
1236
+ builder?: BuilderName | {
1237
+ name: BuilderName;
1238
+ options: BuilderOptions$1;
1239
+ };
1240
+ };
1241
+ typescript?: Partial<TypescriptOptions & TypescriptOptions$1 & TypescriptOptionsReact>;
1242
+ };
1242
1243
  /**
1243
1244
  * The interface for Storybook configuration in `main.ts` files.
1244
1245
  */
1245
- type StorybookConfig = Omit<StorybookConfig$1, keyof StorybookConfigRsbuild | keyof StorybookConfigFramework> & StorybookConfigRsbuild & StorybookConfigFramework & {
1246
- typescript?: Partial<TypescriptOptions>;
1247
- };
1246
+ type StorybookConfig = Omit<StorybookConfig$1, keyof StorybookConfigRsbuild | keyof StorybookConfigFramework> & StorybookConfigRsbuild & StorybookConfigFramework;
1248
1247
 
1249
1248
  export { FrameworkOptions as F, PresetProperty as P, StorybookConfig as S };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { F as FrameworkOptions, S as StorybookConfig } from './index-8cba017d.js';
1
+ export { F as FrameworkOptions, S as StorybookConfig } from './index-0d1103e1.js';
2
2
  import 'storybook-builder-rsbuild';
3
3
  import 'file-system-cache';
4
4
  import 'http';
@@ -103,6 +103,7 @@ function defaultLookupModule(filename, basedir) {
103
103
  // src/loaders/react-docgen-loader.ts
104
104
  var { getNameOrValue, isReactForwardRefCall } = import_react_docgen.utils;
105
105
  var actualNameHandler = function actualNameHandler2(documentation, componentDefinition) {
106
+ documentation.set("definedInFile", componentDefinition.hub.file.opts.filename);
106
107
  if ((componentDefinition.isClassDeclaration() || componentDefinition.isFunctionDeclaration()) && componentDefinition.has("id")) {
107
108
  documentation.set(
108
109
  "actualName",
@@ -133,13 +134,22 @@ var actualNameHandler = function actualNameHandler2(documentation, componentDefi
133
134
  var defaultHandlers = Object.values(import_react_docgen.builtinHandlers).map((handler) => handler);
134
135
  var defaultResolver = new import_react_docgen.builtinResolvers.FindExportedDefinitionsResolver();
135
136
  var handlers = [...defaultHandlers, actualNameHandler];
136
- var tsconfigPathsInitialized = false;
137
+ var tsconfigPathsInitializeStatus = "uninitialized";
138
+ var resolveTsconfigPathsInitialingPromise;
139
+ var tsconfigPathsInitialingPromise = new Promise((resolve2) => {
140
+ resolveTsconfigPathsInitialingPromise = resolve2;
141
+ });
142
+ var finishInitialization = () => {
143
+ resolveTsconfigPathsInitialingPromise();
144
+ tsconfigPathsInitializeStatus = "initialized";
145
+ };
137
146
  var matchPath;
138
147
  async function reactDocgenLoader(source) {
139
148
  const callback = this.async();
140
149
  const options = this.getOptions() || {};
141
150
  const { debug = false } = options;
142
- if (!tsconfigPathsInitialized) {
151
+ if (tsconfigPathsInitializeStatus === "uninitialized") {
152
+ tsconfigPathsInitializeStatus = "initializing";
143
153
  const tsconfigPath = await (0, import_find_up.default)("tsconfig.json", { cwd: process.cwd() });
144
154
  const tsconfig = TsconfigPaths.loadConfig(tsconfigPath);
145
155
  if (tsconfig.resultType === "success") {
@@ -150,7 +160,10 @@ async function reactDocgenLoader(source) {
150
160
  ["browser", "module", "main"]
151
161
  );
152
162
  }
153
- tsconfigPathsInitialized = true;
163
+ finishInitialization();
164
+ }
165
+ if (tsconfigPathsInitializeStatus === "initializing") {
166
+ await tsconfigPathsInitialingPromise;
154
167
  }
155
168
  try {
156
169
  const docgenResults = (0, import_react_docgen.parse)(source, {
@@ -165,8 +178,8 @@ async function reactDocgenLoader(source) {
165
178
  });
166
179
  const magicString = new import_magic_string.default(source);
167
180
  docgenResults.forEach((info) => {
168
- const { actualName, ...docgenInfo } = info;
169
- if (actualName) {
181
+ const { actualName, definedInFile, ...docgenInfo } = info;
182
+ if (actualName && definedInFile === this.resourcePath) {
170
183
  const docNode = JSON.stringify(docgenInfo);
171
184
  magicString.append(`;${actualName}.__docgenInfo=${docNode}`);
172
185
  }
@@ -67,6 +67,7 @@ function defaultLookupModule(filename, basedir) {
67
67
  // src/loaders/react-docgen-loader.ts
68
68
  var { getNameOrValue, isReactForwardRefCall } = utils;
69
69
  var actualNameHandler = function actualNameHandler2(documentation, componentDefinition) {
70
+ documentation.set("definedInFile", componentDefinition.hub.file.opts.filename);
70
71
  if ((componentDefinition.isClassDeclaration() || componentDefinition.isFunctionDeclaration()) && componentDefinition.has("id")) {
71
72
  documentation.set(
72
73
  "actualName",
@@ -97,13 +98,22 @@ var actualNameHandler = function actualNameHandler2(documentation, componentDefi
97
98
  var defaultHandlers = Object.values(builtinHandlers).map((handler) => handler);
98
99
  var defaultResolver = new builtinResolvers.FindExportedDefinitionsResolver();
99
100
  var handlers = [...defaultHandlers, actualNameHandler];
100
- var tsconfigPathsInitialized = false;
101
+ var tsconfigPathsInitializeStatus = "uninitialized";
102
+ var resolveTsconfigPathsInitialingPromise;
103
+ var tsconfigPathsInitialingPromise = new Promise((resolve2) => {
104
+ resolveTsconfigPathsInitialingPromise = resolve2;
105
+ });
106
+ var finishInitialization = () => {
107
+ resolveTsconfigPathsInitialingPromise();
108
+ tsconfigPathsInitializeStatus = "initialized";
109
+ };
101
110
  var matchPath;
102
111
  async function reactDocgenLoader(source) {
103
112
  const callback = this.async();
104
113
  const options = this.getOptions() || {};
105
114
  const { debug = false } = options;
106
- if (!tsconfigPathsInitialized) {
115
+ if (tsconfigPathsInitializeStatus === "uninitialized") {
116
+ tsconfigPathsInitializeStatus = "initializing";
107
117
  const tsconfigPath = await findUp("tsconfig.json", { cwd: process.cwd() });
108
118
  const tsconfig = TsconfigPaths.loadConfig(tsconfigPath);
109
119
  if (tsconfig.resultType === "success") {
@@ -114,7 +124,10 @@ async function reactDocgenLoader(source) {
114
124
  ["browser", "module", "main"]
115
125
  );
116
126
  }
117
- tsconfigPathsInitialized = true;
127
+ finishInitialization();
128
+ }
129
+ if (tsconfigPathsInitializeStatus === "initializing") {
130
+ await tsconfigPathsInitialingPromise;
118
131
  }
119
132
  try {
120
133
  const docgenResults = parse(source, {
@@ -129,8 +142,8 @@ async function reactDocgenLoader(source) {
129
142
  });
130
143
  const magicString = new MagicString(source);
131
144
  docgenResults.forEach((info) => {
132
- const { actualName, ...docgenInfo } = info;
133
- if (actualName) {
145
+ const { actualName, definedInFile, ...docgenInfo } = info;
146
+ if (actualName && definedInFile === this.resourcePath) {
134
147
  const docNode = JSON.stringify(docgenInfo);
135
148
  magicString.append(`;${actualName}.__docgenInfo=${docNode}`);
136
149
  }
package/dist/preset.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { S as StorybookConfig, P as PresetProperty } from './index-8cba017d.js';
1
+ import { S as StorybookConfig, P as PresetProperty } from './index-0d1103e1.js';
2
2
  import 'storybook-builder-rsbuild';
3
3
  import 'file-system-cache';
4
4
  import 'http';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "storybook-react-rsbuild",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "Storybook for React and Rsbuild: Develop React components in isolation with Hot Reloading.",
5
5
  "keywords": [
6
6
  "storybook",
@@ -8,7 +8,6 @@
8
8
  "rspack",
9
9
  "react"
10
10
  ],
11
- "license": "MIT",
12
11
  "bugs": {
13
12
  "url": "https://github.com/rspack-contrib/storybook-rsbuild/issues"
14
13
  },
@@ -17,6 +16,7 @@
17
16
  "url": "https://github.com/rspack-contrib/storybook-rsbuild",
18
17
  "directory": "packages/builder-react"
19
18
  },
19
+ "license": "MIT",
20
20
  "exports": {
21
21
  ".": {
22
22
  "types": "./dist/index.d.ts",
@@ -50,17 +50,22 @@
50
50
  ],
51
51
  "dependencies": {
52
52
  "@rsbuild/core": "0.6.15",
53
- "@storybook/docs-tools": "8.0.10",
54
- "@storybook/node-logger": "8.0.10",
55
- "@storybook/react": "8.0.10",
56
- "@storybook/react-docgen-typescript-plugin": "1.0.1",
53
+ "@storybook/docs-tools": "^8.0.10",
54
+ "@storybook/node-logger": "^8.0.10",
55
+ "@storybook/react": "^8.0.10",
56
+ "@storybook/react-docgen-typescript-plugin": "^1.0.1",
57
57
  "@types/node": "^18.0.0",
58
58
  "find-up": "^5.0.0",
59
59
  "magic-string": "^0.30.10",
60
60
  "react-docgen": "^7.0.3",
61
61
  "resolve": "^1.22.8",
62
62
  "tsconfig-paths": "^4.2.0",
63
- "storybook-builder-rsbuild": "0.0.2"
63
+ "storybook-builder-rsbuild": "0.0.4"
64
+ },
65
+ "devDependencies": {
66
+ "@storybook/types": "^8.0.10",
67
+ "add": "^2.0.6",
68
+ "typescript": "^5.3.2"
64
69
  },
65
70
  "peerDependencies": {
66
71
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0-beta",
@@ -86,11 +91,6 @@
86
91
  ],
87
92
  "platform": "node"
88
93
  },
89
- "devDependencies": {
90
- "@storybook/types": "8.0.10",
91
- "add": "^2.0.6",
92
- "typescript": "^5.3.2"
93
- },
94
94
  "scripts": {
95
95
  "check": "node --loader ../../scripts/node_modules/esbuild-register/loader.js -r ../../scripts/node_modules/esbuild-register/register.js ../../scripts/prepare/check.ts",
96
96
  "prep": "node --loader ../../scripts/node_modules/esbuild-register/loader.js -r ../../scripts/node_modules/esbuild-register/register.js ../../scripts/prepare/bundle.ts"