@storybook/react 10.1.0-alpha.2 → 10.1.0-alpha.3

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 +58 -66
  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_eqmqwiqjsm4 from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_eqmqwiqjsm4 from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_eqmqwiqjsm4 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_eqmqwiqjsm4.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_eqmqwiqjsm4.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_eqmqwiqjsm4.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);
@@ -5151,6 +5125,7 @@ var componentManifestGenerator = /* @__PURE__ */ __name(async () => {
5151
5125
  return {
5152
5126
  name: storyName,
5153
5127
  error: {
5128
+ name: e.name,
5154
5129
  message: e.message
5155
5130
  }
5156
5131
  };
@@ -5164,12 +5139,22 @@ var componentManifestGenerator = /* @__PURE__ */ __name(async () => {
5164
5139
  jsDocTags: {}
5165
5140
  };
5166
5141
  if (!entry.componentPath) {
5167
- const message = `No component file found for the "${name}" component.`;
5142
+ const componentName = csf._meta?.component;
5143
+ const error2 = !componentName ? {
5144
+ name: "No meta.component specified",
5145
+ message: "Specify meta.component for the component to be included in the manifest."
5146
+ } : {
5147
+ name: "No component import found",
5148
+ message: `No component file found for the "${componentName}" component.`
5149
+ };
5168
5150
  return {
5169
5151
  ...base,
5170
5152
  name,
5171
5153
  examples,
5172
- error: { message }
5154
+ error: {
5155
+ name: error2.name,
5156
+ message: csf._metaStatementPath?.buildCodeFrameError(error2.message).message ?? error2.message
5157
+ }
5173
5158
  };
5174
5159
  }
5175
5160
  let componentFile;
@@ -5182,7 +5167,9 @@ var componentManifestGenerator = /* @__PURE__ */ __name(async () => {
5182
5167
  name,
5183
5168
  examples,
5184
5169
  error: {
5185
- message: `Could not read the component file located at ${entry.componentPath}`
5170
+ name: "Component file could not be read",
5171
+ message: `Could not read the component file located at "${entry.componentPath}".
5172
+ Prefer relative imports.`
5186
5173
  }
5187
5174
  };
5188
5175
  }
@@ -5192,7 +5179,12 @@ var componentManifestGenerator = /* @__PURE__ */ __name(async () => {
5192
5179
  });
5193
5180
  const docgen = getMatchingDocgen(docgens, csf);
5194
5181
  const error = !docgen ? {
5195
- message: `Could not parse props information for the located at ${entry.componentPath}`
5182
+ name: "Docgen evaluation failed",
5183
+ message: `Could not parse props information for the component file located at "${entry.componentPath}"
5184
+ Avoid barrel files when importing your component file.
5185
+ Prefer relative imports if possible.
5186
+ Avoid pointing to transpiled files.
5187
+ You can debug your component file in this playground: https://react-docgen.dev/playground`
5196
5188
  } : void 0;
5197
5189
  const metaDescription = extractDescription(csf._metaStatement);
5198
5190
  const jsdocComment = metaDescription || docgen?.description;
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.3",
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.3",
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.3",
84
84
  "typescript": ">= 4.9.x"
85
85
  },
86
86
  "peerDependenciesMeta": {