@storybook/codemod 7.0.0-beta.56 → 7.0.0-beta.57

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/codemod",
3
- "version": "7.0.0-beta.56",
3
+ "version": "7.0.0-beta.57",
4
4
  "description": "A collection of codemod scripts written with JSCodeshift",
5
5
  "keywords": [
6
6
  "storybook"
@@ -45,28 +45,27 @@
45
45
  "prep": "../../../scripts/prepare/bundle.ts"
46
46
  },
47
47
  "dependencies": {
48
- "@babel/core": "^7.20.2",
49
- "@babel/preset-env": "^7.20.2",
50
- "@babel/types": "^7.20.7",
51
48
  "@storybook/csf": "next",
52
- "@storybook/csf-tools": "7.0.0-beta.56",
53
- "@storybook/node-logger": "7.0.0-beta.56",
54
- "@storybook/types": "7.0.0-beta.56",
55
- "cross-spawn": "^7.0.3",
56
- "globby": "^11.0.2",
57
- "jscodeshift": "^0.14.0",
58
- "lodash": "^4.17.21",
59
- "prettier": "^2.8.0",
60
- "recast": "^0.23.1",
61
- "util": "^0.12.4"
49
+ "@storybook/csf-tools": "7.0.0-beta.57",
50
+ "@storybook/node-logger": "7.0.0-beta.57",
51
+ "@storybook/types": "7.0.0-beta.57",
52
+ "recast": "^0.23.1"
62
53
  },
63
54
  "devDependencies": {
55
+ "@babel/core": "^7.21.0",
56
+ "@babel/preset-env": "^7.20.2",
57
+ "@babel/types": "^7.21.2",
64
58
  "@types/jscodeshift": "^0.11.6",
65
59
  "ansi-regex": "^5.0.1",
60
+ "cross-spawn": "^7.0.3",
61
+ "globby": "^11.0.2",
66
62
  "jest": "^29.3.1",
67
63
  "jest-specific-snapshot": "^7.0.0",
64
+ "jscodeshift": "^0.14.0",
65
+ "lodash": "^4.17.21",
68
66
  "mdast-util-mdx-jsx": "^2.1.2",
69
67
  "mdast-util-mdxjs-esm": "^1.3.1",
68
+ "prettier": "^2.8.0",
70
69
  "remark": "^14.0.2",
71
70
  "remark-mdx": "^2.2.1",
72
71
  "ts-dedent": "^2.2.0",
@@ -74,6 +73,7 @@
74
73
  "unist-util-is": "^5.2.0",
75
74
  "unist-util-select": "^4.0.3",
76
75
  "unist-util-visit": "^4.1.2",
76
+ "util": "^0.12.4",
77
77
  "vfile": "^5.3.7"
78
78
  },
79
79
  "publishConfig": {
@@ -97,5 +97,5 @@
97
97
  "cjs"
98
98
  ]
99
99
  },
100
- "gitHead": "26815b0ea07f3800cc514cccd242c8ab1f428b8c"
100
+ "gitHead": "40424e73ad881740b16d5017507f7790fe8d27c5"
101
101
  }
@@ -140,7 +140,7 @@ export default function transform(info: FileInfo, api: API, options: { parser?:
140
140
  // Remove the render function when we can hoist the template
141
141
  // const Template = (args) => <Cat {...args} />;
142
142
  // export const A = Template.bind({});
143
- let storyFn = template && csf._templates[template];
143
+ let storyFn: t.Expression = template && (csf._templates[template] as any as t.Expression);
144
144
  if (!storyFn) {
145
145
  storyFn = init;
146
146
  }
@@ -163,20 +163,24 @@ export default function transform(info: FileInfo, api: API, options: { parser?:
163
163
  importHelper.removeDeprecatedStoryImport();
164
164
 
165
165
  csf._ast.program.body = csf._ast.program.body.reduce((acc, stmt) => {
166
+ const statement = stmt as t.Statement;
166
167
  // remove story annotations & template declarations
167
- if (isStoryAnnotation(stmt, objectExports) || isTemplateDeclaration(stmt, csf._templates)) {
168
+ if (
169
+ isStoryAnnotation(statement, objectExports) ||
170
+ isTemplateDeclaration(statement, csf._templates)
171
+ ) {
168
172
  return acc;
169
173
  }
170
174
 
171
175
  // replace story exports with new object exports
172
- const newExport = getNewExport(stmt, objectExports);
176
+ const newExport = getNewExport(statement, objectExports);
173
177
  if (newExport) {
174
178
  acc.push(newExport);
175
179
  return acc;
176
180
  }
177
181
 
178
182
  // include unknown statements
179
- acc.push(stmt);
183
+ acc.push(statement);
180
184
  return acc;
181
185
  }, []);
182
186
 
@@ -179,7 +179,10 @@ export function transform(source: string, baseName: string): [mdx: string, csf:
179
179
  return [t.objectProperty(t.identifier(attribute.name), t.stringLiteral(attribute.value))];
180
180
  }
181
181
  return [
182
- t.objectProperty(t.identifier(attribute.name), babelParseExpression(attribute.value.value)),
182
+ t.objectProperty(
183
+ t.identifier(attribute.name),
184
+ babelParseExpression(attribute.value.value) as any as t.Expression
185
+ ),
183
186
  ];
184
187
  }
185
188
  return [];
@@ -216,7 +219,7 @@ export function transform(source: string, baseName: string): [mdx: string, csf:
216
219
  return t.arrowFunctionExpression([], t.stringLiteral(child.value));
217
220
  }
218
221
  if (child.type === 'mdxFlowExpression' || child.type === 'mdxTextExpression') {
219
- const expression = babelParseExpression(child.value);
222
+ const expression = babelParseExpression(child.value) as any as t.Expression;
220
223
 
221
224
  // Recreating those lines: https://github.com/storybookjs/mdx1-csf/blob/f408fc97e9a63097ca1ee577df9315a3cccca975/src/sb-mdx-plugin.ts#L185-L198
222
225
  const BIND_REGEX = /\.bind\(.*\)/;
@@ -234,7 +237,7 @@ export function transform(source: string, baseName: string): [mdx: string, csf:
234
237
 
235
238
  const expression = babelParseExpression(
236
239
  mdxProcessor.stringify({ type: 'root', children: [child] })
237
- );
240
+ ) as any as t.Expression;
238
241
  return t.arrowFunctionExpression([], expression);
239
242
  }
240
243
 
@@ -272,7 +275,7 @@ export function transform(source: string, baseName: string): [mdx: string, csf:
272
275
  return [
273
276
  t.objectProperty(
274
277
  t.identifier(attribute.name),
275
- babelParseExpression(attribute.value.value)
278
+ babelParseExpression(attribute.value.value) as any as t.Expression
276
279
  ),
277
280
  ];
278
281
  }