storybook-react-rsbuild 0.0.3 → 0.0.5

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';
@@ -869,7 +869,7 @@ interface DirectoryMapping {
869
869
  to: string;
870
870
  }
871
871
  interface Presets {
872
- apply(extension: 'typescript', config: TypescriptOptions$1, args?: Options): Promise<TypescriptOptions$1>;
872
+ apply(extension: 'typescript', config: TypescriptOptions, args?: Options): Promise<TypescriptOptions>;
873
873
  apply(extension: 'framework', config?: {}, args?: any): Promise<Preset>;
874
874
  apply(extension: 'babel', config?: {}, args?: any): Promise<any>;
875
875
  apply(extension: 'swc', config?: {}, args?: any): Promise<any>;
@@ -956,7 +956,7 @@ type Options = LoadOptions & StorybookConfigOptions & CLIOptions & BuilderOption
956
956
  /**
957
957
  * Options for TypeScript usage within Storybook.
958
958
  */
959
- interface TypescriptOptions$1 {
959
+ interface TypescriptOptions {
960
960
  /**
961
961
  * Enables type checking within Storybook.
962
962
  *
@@ -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-8df66448.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';
@@ -4,7 +4,7 @@ import { LoaderContext } from 'webpack';
4
4
 
5
5
  declare function reactDocgenLoader(this: LoaderContext<{
6
6
  debug: boolean;
7
- }>, source: string): Promise<void>;
7
+ }>, source: string, map: any): Promise<void>;
8
8
  declare function getReactDocgenImporter(matchingPath: TsconfigPaths.MatchPath | undefined): react_docgen.Importer;
9
9
 
10
10
  export { reactDocgenLoader as default, getReactDocgenImporter };
@@ -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",
@@ -143,7 +144,7 @@ var finishInitialization = () => {
143
144
  tsconfigPathsInitializeStatus = "initialized";
144
145
  };
145
146
  var matchPath;
146
- async function reactDocgenLoader(source) {
147
+ async function reactDocgenLoader(source, map) {
147
148
  const callback = this.async();
148
149
  const options = this.getOptions() || {};
149
150
  const { debug = false } = options;
@@ -177,17 +178,21 @@ async function reactDocgenLoader(source) {
177
178
  });
178
179
  const magicString = new import_magic_string.default(source);
179
180
  docgenResults.forEach((info) => {
180
- const { actualName, ...docgenInfo } = info;
181
- if (actualName) {
181
+ const { actualName, definedInFile, ...docgenInfo } = info;
182
+ if (actualName && definedInFile === this.resourcePath) {
182
183
  const docNode = JSON.stringify(docgenInfo);
183
184
  magicString.append(`;${actualName}.__docgenInfo=${docNode}`);
184
185
  }
185
186
  });
186
- const map = magicString.generateMap({
187
- includeContent: true,
188
- source: this.resourcePath
189
- });
190
- callback(null, magicString.toString(), map);
187
+ callback(
188
+ null,
189
+ magicString.toString(),
190
+ map ?? magicString.generateMap({
191
+ hires: true,
192
+ source: this.resourcePath,
193
+ includeContent: true
194
+ })
195
+ );
191
196
  } catch (error) {
192
197
  if (error.code === import_react_docgen.ERROR_CODES.MISSING_DEFINITION) {
193
198
  callback(null, source);
@@ -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",
@@ -107,7 +108,7 @@ var finishInitialization = () => {
107
108
  tsconfigPathsInitializeStatus = "initialized";
108
109
  };
109
110
  var matchPath;
110
- async function reactDocgenLoader(source) {
111
+ async function reactDocgenLoader(source, map) {
111
112
  const callback = this.async();
112
113
  const options = this.getOptions() || {};
113
114
  const { debug = false } = options;
@@ -141,17 +142,21 @@ async function reactDocgenLoader(source) {
141
142
  });
142
143
  const magicString = new MagicString(source);
143
144
  docgenResults.forEach((info) => {
144
- const { actualName, ...docgenInfo } = info;
145
- if (actualName) {
145
+ const { actualName, definedInFile, ...docgenInfo } = info;
146
+ if (actualName && definedInFile === this.resourcePath) {
146
147
  const docNode = JSON.stringify(docgenInfo);
147
148
  magicString.append(`;${actualName}.__docgenInfo=${docNode}`);
148
149
  }
149
150
  });
150
- const map = magicString.generateMap({
151
- includeContent: true,
152
- source: this.resourcePath
153
- });
154
- callback(null, magicString.toString(), map);
151
+ callback(
152
+ null,
153
+ magicString.toString(),
154
+ map ?? magicString.generateMap({
155
+ hires: true,
156
+ source: this.resourcePath,
157
+ includeContent: true
158
+ })
159
+ );
155
160
  } catch (error) {
156
161
  if (error.code === ERROR_CODES.MISSING_DEFINITION) {
157
162
  callback(null, source);
package/dist/preset.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { S as StorybookConfig, P as PresetProperty } from './index-8df66448.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.3",
3
+ "version": "0.0.5",
4
4
  "description": "Storybook for React and Rsbuild: Develop React components in isolation with Hot Reloading.",
5
5
  "keywords": [
6
6
  "storybook",
@@ -60,10 +60,11 @@
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.3"
63
+ "storybook-builder-rsbuild": "0.0.5"
64
64
  },
65
65
  "devDependencies": {
66
66
  "@storybook/types": "^8.0.10",
67
+ "@types/resolve": "^1.20.6",
67
68
  "add": "^2.0.6",
68
69
  "typescript": "^5.3.2"
69
70
  },