@storybook/codemod 7.0.0-beta.2 → 7.0.0-beta.21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. package/dist/chunk-3OPQTROG.mjs +1 -0
  2. package/dist/chunk-B5FMQ3BX.mjs +1 -0
  3. package/dist/chunk-HBPKIMKE.mjs +1 -0
  4. package/dist/index.d.ts +13 -261
  5. package/dist/index.js +1 -1
  6. package/dist/index.mjs +1 -1
  7. package/dist/transforms/add-component-parameters.d.ts +22 -0
  8. package/dist/transforms/add-component-parameters.js +1 -0
  9. package/dist/transforms/add-component-parameters.mjs +1 -0
  10. package/dist/transforms/csf-2-to-3.d.ts +6 -0
  11. package/dist/transforms/csf-2-to-3.js +1 -0
  12. package/dist/transforms/csf-2-to-3.mjs +1 -0
  13. package/dist/transforms/csf-hoist-story-annotations.d.ts +26 -0
  14. package/dist/transforms/csf-hoist-story-annotations.js +1 -0
  15. package/dist/transforms/csf-hoist-story-annotations.mjs +1 -0
  16. package/dist/transforms/csf-to-mdx.d.ts +29 -0
  17. package/dist/transforms/csf-to-mdx.js +3 -0
  18. package/dist/transforms/csf-to-mdx.mjs +3 -0
  19. package/dist/transforms/move-builtin-addons.d.ts +3 -0
  20. package/dist/transforms/move-builtin-addons.js +1 -0
  21. package/dist/transforms/move-builtin-addons.mjs +1 -0
  22. package/dist/transforms/storiesof-to-csf.d.ts +24 -0
  23. package/dist/transforms/storiesof-to-csf.js +1 -0
  24. package/dist/transforms/storiesof-to-csf.mjs +1 -0
  25. package/dist/transforms/update-addon-info.d.ts +27 -0
  26. package/dist/transforms/update-addon-info.js +1 -0
  27. package/dist/transforms/update-addon-info.mjs +1 -0
  28. package/dist/transforms/update-organisation-name.d.ts +25 -0
  29. package/dist/transforms/update-organisation-name.js +1 -0
  30. package/dist/transforms/update-organisation-name.mjs +1 -0
  31. package/dist/transforms/upgrade-hierarchy-separators.d.ts +3 -0
  32. package/dist/transforms/upgrade-hierarchy-separators.js +1 -0
  33. package/dist/transforms/upgrade-hierarchy-separators.mjs +1 -0
  34. package/package.json +28 -7
  35. package/src/index.js +11 -1
  36. package/src/lib/utils.ts +2 -2
  37. package/src/transforms/__testfixtures__/csf-to-mdx/decorators.input.js +1 -1
  38. package/src/transforms/__testfixtures__/csf-to-mdx/story-function.input.js +1 -1
  39. package/src/transforms/__testfixtures__/csf-to-mdx/story-function.output.snapshot +1 -1
  40. package/src/transforms/__testfixtures__/mdx-to-csf/{basic.input.js → basic.input.mdx} +0 -0
  41. package/src/transforms/__testfixtures__/mdx-to-csf/{component-id.input.js → component-id.input.mdx} +0 -0
  42. package/src/transforms/__testfixtures__/mdx-to-csf/{decorators.input.js → decorators.input.mdx} +0 -0
  43. package/src/transforms/__testfixtures__/mdx-to-csf/{exclude-stories.input.js → exclude-stories.input.mdx} +0 -0
  44. package/src/transforms/__testfixtures__/mdx-to-csf/{parameters.input.js → parameters.input.mdx} +0 -0
  45. package/src/transforms/__testfixtures__/mdx-to-csf/{plaintext.input.js → plaintext.input.mdx} +0 -0
  46. package/src/transforms/__testfixtures__/mdx-to-csf/{story-function.input.js → story-function.input.mdx} +0 -0
  47. package/src/transforms/__testfixtures__/mdx-to-csf/{story-parameters.input.js → story-parameters.input.mdx} +0 -0
  48. package/src/transforms/__testfixtures__/mdx-to-csf/{story-refs.input.js → story-refs.input.mdx} +0 -0
  49. package/src/transforms/__testfixtures__/storiesof-to-csf/decorators.input.js +1 -1
  50. package/src/transforms/__testfixtures__/storiesof-to-csf/export-function.input.js +1 -1
  51. package/src/transforms/__testfixtures__/storiesof-to-csf/story-decorators.input.js +1 -1
  52. package/src/transforms/__testfixtures__/update-addon-info/update-addon-info.input.js +34 -48
  53. package/src/transforms/__testfixtures__/update-addon-info/update-addon-info.output.snapshot +33 -47
  54. package/src/transforms/__tests__/csf-2-to-3.test.ts +5 -3
  55. package/src/transforms/csf-2-to-3.ts +23 -16
  56. package/tsconfig.json +4 -2
@@ -1,4 +1,4 @@
1
- import { describe, it, expect } from '@jest/globals';
1
+ // import { describe, it, expect } from '@jest/globals';
2
2
  import { dedent } from 'ts-dedent';
3
3
  import _transform from '../csf-2-to-3';
4
4
 
@@ -7,8 +7,10 @@ expect.addSnapshotSerializer({
7
7
  test: () => true,
8
8
  });
9
9
 
10
- const jsTransform = (source: string) => _transform({ source }, null, {}).trim();
11
- const tsTransform = (source: string) => _transform({ source }, null, { parser: 'tsx' }).trim();
10
+ const jsTransform = (source: string) =>
11
+ _transform({ source, path: 'Component.stories.js' }, null, {}).trim();
12
+ const tsTransform = (source: string) =>
13
+ _transform({ source, path: 'Component.stories.ts' }, null, { parser: 'tsx' }).trim();
12
14
 
13
15
  describe('csf-2-to-3', () => {
14
16
  describe('javascript', () => {
@@ -3,7 +3,7 @@ import prettier from 'prettier';
3
3
  import * as t from '@babel/types';
4
4
  import type { CsfFile } from '@storybook/csf-tools';
5
5
  import { formatCsf, loadCsf } from '@storybook/csf-tools';
6
- import { jscodeshiftToPrettierParser } from '../lib/utils';
6
+ import type { API, FileInfo, Options } from 'jscodeshift';
7
7
 
8
8
  const logger = console;
9
9
 
@@ -89,7 +89,7 @@ const isReactGlobalRenderFn = (csf: CsfFile, storyFn: t.Expression) => {
89
89
  const isSimpleCSFStory = (init: t.Expression, annotations: t.ObjectProperty[]) =>
90
90
  annotations.length === 0 && t.isArrowFunctionExpression(init) && init.params.length === 0;
91
91
 
92
- function transform({ source }: { source: string }, api: any, options: { parser?: string }) {
92
+ export default function transform({ source, path }: FileInfo, api: API, options: Options) {
93
93
  const makeTitle = (userTitle?: string) => {
94
94
  return userTitle || 'FIXME';
95
95
  };
@@ -165,20 +165,27 @@ function transform({ source }: { source: string }, api: any, options: { parser?:
165
165
  return acc;
166
166
  }, []);
167
167
  csf._ast.program.body = updatedBody;
168
- const output = formatCsf(csf);
169
-
170
- const prettierConfig = prettier.resolveConfig.sync('.', { editorconfig: true }) || {
171
- printWidth: 100,
172
- tabWidth: 2,
173
- bracketSpacing: true,
174
- trailingComma: 'es5',
175
- singleQuote: true,
176
- };
168
+ let output = formatCsf(csf);
177
169
 
178
- return prettier.format(output, {
179
- ...prettierConfig,
180
- parser: jscodeshiftToPrettierParser(options?.parser),
181
- });
170
+ try {
171
+ const prettierConfig = prettier.resolveConfig.sync('.', { editorconfig: true }) || {
172
+ printWidth: 100,
173
+ tabWidth: 2,
174
+ bracketSpacing: true,
175
+ trailingComma: 'es5',
176
+ singleQuote: true,
177
+ };
178
+
179
+ output = prettier.format(output, {
180
+ ...prettierConfig,
181
+ // This will infer the parser from the filename.
182
+ filepath: path,
183
+ });
184
+ } catch (e) {
185
+ logger.log(`Failed applying prettier to ${path}.`);
186
+ }
187
+
188
+ return output;
182
189
  }
183
190
 
184
- export default transform;
191
+ export const parser = 'tsx';
package/tsconfig.json CHANGED
@@ -1,7 +1,9 @@
1
1
  {
2
2
  "extends": "../../tsconfig.json",
3
3
  "compilerOptions": {
4
- "skipLibCheck": true
4
+ "skipLibCheck": true,
5
+ "allowJs": true
5
6
  },
6
- "include": ["src/**/*"]
7
+ "include": ["src/**/*"],
8
+ "exclude": ["node_modules", "__testfixtures__", "__tests__"]
7
9
  }