@storybook/react 10.1.0-alpha.2 → 10.1.0-alpha.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.
Files changed (2) hide show
  1. package/dist/preset.js +63 -74
  2. package/package.json +3 -3
package/dist/preset.js CHANGED
@@ -1,10 +1,10 @@
1
- import CJS_COMPAT_NODE_URL_1skdcz3rbd6 from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_1skdcz3rbd6 from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_1skdcz3rbd6 from "node:module";
1
+ import CJS_COMPAT_NODE_URL_ou6ur9ka85b from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_ou6ur9ka85b from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_ou6ur9ka85b from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_1skdcz3rbd6.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_1skdcz3rbd6.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_1skdcz3rbd6.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_ou6ur9ka85b.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_ou6ur9ka85b.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_ou6ur9ka85b.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
@@ -4065,7 +4065,9 @@ function getCodeSnippet(csf, storyName, componentName) {
4065
4065
  const metaArgs = metaArgsRecord(metaObj ?? null);
4066
4066
  const storyArgsPath = storyProps.filter((p) => keyOf(p.node) === "args").map((p) => p.get("value")).find((v) => v.isObjectExpression());
4067
4067
  const storyArgs = argsRecordFromObjectPath(storyArgsPath);
4068
- const merged = { ...metaArgs, ...storyArgs };
4068
+ const storyAssignedArgsPath = storyArgsAssignmentPath(csf._file.path, storyName);
4069
+ const storyAssignedArgs = argsRecordFromObjectPath(storyAssignedArgsPath);
4070
+ const merged = { ...metaArgs, ...storyArgs, ...storyAssignedArgs };
4069
4071
  const entries = Object.entries(merged).filter(([k]) => k !== "children");
4070
4072
  const validEntries = entries.filter(([k, v]) => isValidJsxAttrName(k) && v != null);
4071
4073
  const invalidEntries = entries.filter(([k, v]) => !isValidJsxAttrName(k) && v != null);
@@ -4138,6 +4140,26 @@ var isValidJsxAttrName = /* @__PURE__ */ __name((n) => /^[A-Za-z_][A-Za-z0-9_:-]
4138
4140
  var argsRecordFromObjectPath = /* @__PURE__ */ __name((objPath) => objPath ? Object.fromEntries(
4139
4141
  objPath.get("properties").filter((p) => p.isObjectProperty()).map((p) => [keyOf(p.node), p.get("value").node]).filter((e) => Boolean(e[0]))
4140
4142
  ) : {}, "argsRecordFromObjectPath");
4143
+ function storyArgsAssignmentPath(program, storyName) {
4144
+ let found = null;
4145
+ program.traverse({
4146
+ AssignmentExpression(p) {
4147
+ const left = p.get("left");
4148
+ const right = p.get("right");
4149
+ if (left.isMemberExpression()) {
4150
+ const obj = left.get("object");
4151
+ const prop = left.get("property");
4152
+ const isStoryIdent = obj.isIdentifier() && obj.node.name === storyName;
4153
+ const isArgsProp = prop.isIdentifier() && prop.node.name === "args" && !left.node.computed || t.isStringLiteral(prop.node) && left.node.computed && prop.node.value === "args";
4154
+ if (isStoryIdent && isArgsProp && right.isObjectExpression()) {
4155
+ found = right;
4156
+ }
4157
+ }
4158
+ }
4159
+ });
4160
+ return found;
4161
+ }
4162
+ __name(storyArgsAssignmentPath, "storyArgsAssignmentPath");
4141
4163
  var argsRecordFromObjectNode = /* @__PURE__ */ __name((obj) => obj ? Object.fromEntries(
4142
4164
  obj.properties.filter((p) => t.isObjectProperty(p)).map((p) => [keyOf(p), p.value]).filter((e) => Boolean(e[0]))
4143
4165
  ) : {}, "argsRecordFromObjectNode");
@@ -4769,6 +4791,8 @@ import { existsSync as existsSync2 } from "node:fs";
4769
4791
  import { sep as sep2 } from "node:path";
4770
4792
  import { types as t2 } from "storybook/internal/babel";
4771
4793
  import { getProjectRoot } from "storybook/internal/common";
4794
+ import { supportedExtensions as supportedExtensions2 } from "storybook/internal/common";
4795
+ import { resolveImport } from "storybook/internal/common";
4772
4796
 
4773
4797
  // ../../node_modules/empathic/find.mjs
4774
4798
  import { join as join4 } from "node:path";
@@ -4853,7 +4877,7 @@ var actualNameHandler_default = actualNameHandler;
4853
4877
 
4854
4878
  // src/componentManifest/reactDocgen/docgenResolver.ts
4855
4879
  var import_resolve2 = __toESM(require_resolve(), 1);
4856
- import { extname as extname2 } from "node:path";
4880
+ import { supportedExtensions } from "storybook/internal/common";
4857
4881
  var ReactDocgenResolveError = class extends Error {
4858
4882
  constructor(filename) {
4859
4883
  super(`'${filename}' was ignored by react-docgen.`);
@@ -4864,56 +4888,6 @@ var ReactDocgenResolveError = class extends Error {
4864
4888
  __name(this, "ReactDocgenResolveError");
4865
4889
  }
4866
4890
  };
4867
- var RESOLVE_EXTENSIONS = [
4868
- ".js",
4869
- ".cts",
4870
- // These were originally not in the code, I added them
4871
- ".mts",
4872
- // These were originally not in the code, I added them
4873
- ".ctsx",
4874
- // These were originally not in the code, I added them
4875
- ".mtsx",
4876
- // These were originally not in the code, I added them
4877
- ".ts",
4878
- ".tsx",
4879
- ".mjs",
4880
- ".cjs",
4881
- ".mts",
4882
- ".cts",
4883
- ".jsx"
4884
- ];
4885
- function defaultLookupModule(filename, basedir) {
4886
- const resolveOptions = {
4887
- basedir,
4888
- extensions: RESOLVE_EXTENSIONS,
4889
- // we do not need to check core modules as we cannot import them anyway
4890
- includeCoreModules: false
4891
- };
4892
- try {
4893
- return import_resolve2.default.sync(filename, resolveOptions);
4894
- } catch (error) {
4895
- const ext = extname2(filename);
4896
- let newFilename;
4897
- switch (ext) {
4898
- case ".js":
4899
- case ".mjs":
4900
- case ".cjs":
4901
- newFilename = `${filename.slice(0, -2)}ts`;
4902
- break;
4903
- case ".jsx":
4904
- newFilename = `${filename.slice(0, -3)}tsx`;
4905
- break;
4906
- default:
4907
- throw error;
4908
- }
4909
- return import_resolve2.default.sync(newFilename, {
4910
- ...resolveOptions,
4911
- // we already know that there is an extension at this point, so no need to check other extensions
4912
- extensions: []
4913
- });
4914
- }
4915
- }
4916
- __name(defaultLookupModule, "defaultLookupModule");
4917
4891
 
4918
4892
  // src/componentManifest/reactDocgen/exportNameHandler.ts
4919
4893
  import { utils as utils2 } from "react-docgen";
@@ -5096,25 +5070,25 @@ function getReactDocgenImporter(matchPath) {
5096
5070
  return makeFsImporter((filename, basedir) => {
5097
5071
  const mappedFilenameByPaths = (() => {
5098
5072
  if (matchPath) {
5099
- const match = matchPath(filename);
5073
+ const match = matchPath(filename, void 0, void 0, supportedExtensions2);
5100
5074
  return match || filename;
5101
5075
  } else {
5102
5076
  return filename;
5103
5077
  }
5104
5078
  })();
5105
- const result = defaultLookupModule(mappedFilenameByPaths, basedir);
5079
+ const result = resolveImport(mappedFilenameByPaths, { basedir });
5106
5080
  if (result.includes(`${sep2}react-native${sep2}index.js`)) {
5107
5081
  const replaced = result.replace(
5108
5082
  `${sep2}react-native${sep2}index.js`,
5109
5083
  `${sep2}react-native-web${sep2}dist${sep2}index.js`
5110
5084
  );
5111
5085
  if (existsSync2(replaced)) {
5112
- if (RESOLVE_EXTENSIONS.find((ext) => result.endsWith(ext))) {
5086
+ if (supportedExtensions2.find((ext) => result.endsWith(ext))) {
5113
5087
  return replaced;
5114
5088
  }
5115
5089
  }
5116
5090
  }
5117
- if (RESOLVE_EXTENSIONS.find((ext) => result.endsWith(ext))) {
5091
+ if (supportedExtensions2.find((ext) => result.endsWith(ext))) {
5118
5092
  return result;
5119
5093
  }
5120
5094
  throw new ReactDocgenResolveError(filename);
@@ -5140,7 +5114,7 @@ var componentManifestGenerator = /* @__PURE__ */ __name(async () => {
5140
5114
  const name = csf._meta?.component ?? entry.title.split("/").at(-1);
5141
5115
  const id = entry.id.split("--")[0];
5142
5116
  const importPath = entry.importPath;
5143
- const examples = Object.keys(csf._stories).map((storyName) => {
5117
+ const stories = Object.keys(csf._stories).map((storyName) => {
5144
5118
  try {
5145
5119
  return {
5146
5120
  name: storyName,
@@ -5150,9 +5124,7 @@ var componentManifestGenerator = /* @__PURE__ */ __name(async () => {
5150
5124
  invariant(e instanceof Error);
5151
5125
  return {
5152
5126
  name: storyName,
5153
- error: {
5154
- message: e.message
5155
- }
5127
+ error: { name: e.name, message: e.message }
5156
5128
  };
5157
5129
  }
5158
5130
  }).filter(Boolean);
@@ -5160,16 +5132,26 @@ var componentManifestGenerator = /* @__PURE__ */ __name(async () => {
5160
5132
  id,
5161
5133
  name,
5162
5134
  path: importPath,
5163
- examples,
5135
+ stories,
5164
5136
  jsDocTags: {}
5165
5137
  };
5166
5138
  if (!entry.componentPath) {
5167
- const message = `No component file found for the "${name}" component.`;
5139
+ const componentName = csf._meta?.component;
5140
+ const error2 = !componentName ? {
5141
+ name: "No meta.component specified",
5142
+ message: "Specify meta.component for the component to be included in the manifest."
5143
+ } : {
5144
+ name: "No component import found",
5145
+ message: `No component file found for the "${componentName}" component.`
5146
+ };
5168
5147
  return {
5169
5148
  ...base,
5170
5149
  name,
5171
- examples,
5172
- error: { message }
5150
+ stories,
5151
+ error: {
5152
+ name: error2.name,
5153
+ message: csf._metaStatementPath?.buildCodeFrameError(error2.message).message ?? error2.message
5154
+ }
5173
5155
  };
5174
5156
  }
5175
5157
  let componentFile;
@@ -5180,9 +5162,11 @@ var componentManifestGenerator = /* @__PURE__ */ __name(async () => {
5180
5162
  return {
5181
5163
  ...base,
5182
5164
  name,
5183
- examples,
5165
+ stories,
5184
5166
  error: {
5185
- message: `Could not read the component file located at ${entry.componentPath}`
5167
+ name: "Component file could not be read",
5168
+ message: `Could not read the component file located at "${entry.componentPath}".
5169
+ Prefer relative imports.`
5186
5170
  }
5187
5171
  };
5188
5172
  }
@@ -5192,7 +5176,12 @@ var componentManifestGenerator = /* @__PURE__ */ __name(async () => {
5192
5176
  });
5193
5177
  const docgen = getMatchingDocgen(docgens, csf);
5194
5178
  const error = !docgen ? {
5195
- message: `Could not parse props information for the located at ${entry.componentPath}`
5179
+ name: "Docgen evaluation failed",
5180
+ message: `Could not parse props information for the component file located at "${entry.componentPath}"
5181
+ Avoid barrel files when importing your component file.
5182
+ Prefer relative imports if possible.
5183
+ Avoid pointing to transpiled files.
5184
+ You can debug your component file in this playground: https://react-docgen.dev/playground`
5196
5185
  } : void 0;
5197
5186
  const metaDescription = extractDescription(csf._metaStatement);
5198
5187
  const jsdocComment = metaDescription || docgen?.description;
@@ -5206,7 +5195,7 @@ var componentManifestGenerator = /* @__PURE__ */ __name(async () => {
5206
5195
  import: tags.import?.[0],
5207
5196
  reactDocgen: docgen,
5208
5197
  jsDocTags: tags,
5209
- examples,
5198
+ stories,
5210
5199
  error
5211
5200
  };
5212
5201
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/react",
3
- "version": "10.1.0-alpha.2",
3
+ "version": "10.1.0-alpha.4",
4
4
  "description": "Storybook React renderer",
5
5
  "keywords": [
6
6
  "storybook"
@@ -54,7 +54,7 @@
54
54
  },
55
55
  "dependencies": {
56
56
  "@storybook/global": "^5.0.0",
57
- "@storybook/react-dom-shim": "10.1.0-alpha.2",
57
+ "@storybook/react-dom-shim": "10.1.0-alpha.4",
58
58
  "react-docgen": "^8.0.2"
59
59
  },
60
60
  "devDependencies": {
@@ -80,7 +80,7 @@
80
80
  "peerDependencies": {
81
81
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
82
82
  "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
83
- "storybook": "^10.1.0-alpha.2",
83
+ "storybook": "^10.1.0-alpha.4",
84
84
  "typescript": ">= 4.9.x"
85
85
  },
86
86
  "peerDependenciesMeta": {