@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.
- package/dist/chunk-3OPQTROG.mjs +1 -0
- package/dist/chunk-B5FMQ3BX.mjs +1 -0
- package/dist/chunk-HBPKIMKE.mjs +1 -0
- package/dist/index.d.ts +13 -261
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/transforms/add-component-parameters.d.ts +22 -0
- package/dist/transforms/add-component-parameters.js +1 -0
- package/dist/transforms/add-component-parameters.mjs +1 -0
- package/dist/transforms/csf-2-to-3.d.ts +6 -0
- package/dist/transforms/csf-2-to-3.js +1 -0
- package/dist/transforms/csf-2-to-3.mjs +1 -0
- package/dist/transforms/csf-hoist-story-annotations.d.ts +26 -0
- package/dist/transforms/csf-hoist-story-annotations.js +1 -0
- package/dist/transforms/csf-hoist-story-annotations.mjs +1 -0
- package/dist/transforms/csf-to-mdx.d.ts +29 -0
- package/dist/transforms/csf-to-mdx.js +3 -0
- package/dist/transforms/csf-to-mdx.mjs +3 -0
- package/dist/transforms/move-builtin-addons.d.ts +3 -0
- package/dist/transforms/move-builtin-addons.js +1 -0
- package/dist/transforms/move-builtin-addons.mjs +1 -0
- package/dist/transforms/storiesof-to-csf.d.ts +24 -0
- package/dist/transforms/storiesof-to-csf.js +1 -0
- package/dist/transforms/storiesof-to-csf.mjs +1 -0
- package/dist/transforms/update-addon-info.d.ts +27 -0
- package/dist/transforms/update-addon-info.js +1 -0
- package/dist/transforms/update-addon-info.mjs +1 -0
- package/dist/transforms/update-organisation-name.d.ts +25 -0
- package/dist/transforms/update-organisation-name.js +1 -0
- package/dist/transforms/update-organisation-name.mjs +1 -0
- package/dist/transforms/upgrade-hierarchy-separators.d.ts +3 -0
- package/dist/transforms/upgrade-hierarchy-separators.js +1 -0
- package/dist/transforms/upgrade-hierarchy-separators.mjs +1 -0
- package/package.json +28 -7
- package/src/index.js +11 -1
- package/src/lib/utils.ts +2 -2
- package/src/transforms/__testfixtures__/csf-to-mdx/decorators.input.js +1 -1
- package/src/transforms/__testfixtures__/csf-to-mdx/story-function.input.js +1 -1
- package/src/transforms/__testfixtures__/csf-to-mdx/story-function.output.snapshot +1 -1
- package/src/transforms/__testfixtures__/mdx-to-csf/{basic.input.js → basic.input.mdx} +0 -0
- package/src/transforms/__testfixtures__/mdx-to-csf/{component-id.input.js → component-id.input.mdx} +0 -0
- package/src/transforms/__testfixtures__/mdx-to-csf/{decorators.input.js → decorators.input.mdx} +0 -0
- package/src/transforms/__testfixtures__/mdx-to-csf/{exclude-stories.input.js → exclude-stories.input.mdx} +0 -0
- package/src/transforms/__testfixtures__/mdx-to-csf/{parameters.input.js → parameters.input.mdx} +0 -0
- package/src/transforms/__testfixtures__/mdx-to-csf/{plaintext.input.js → plaintext.input.mdx} +0 -0
- package/src/transforms/__testfixtures__/mdx-to-csf/{story-function.input.js → story-function.input.mdx} +0 -0
- package/src/transforms/__testfixtures__/mdx-to-csf/{story-parameters.input.js → story-parameters.input.mdx} +0 -0
- package/src/transforms/__testfixtures__/mdx-to-csf/{story-refs.input.js → story-refs.input.mdx} +0 -0
- package/src/transforms/__testfixtures__/storiesof-to-csf/decorators.input.js +1 -1
- package/src/transforms/__testfixtures__/storiesof-to-csf/export-function.input.js +1 -1
- package/src/transforms/__testfixtures__/storiesof-to-csf/story-decorators.input.js +1 -1
- package/src/transforms/__testfixtures__/update-addon-info/update-addon-info.input.js +34 -48
- package/src/transforms/__testfixtures__/update-addon-info/update-addon-info.output.snapshot +33 -47
- package/src/transforms/__tests__/csf-2-to-3.test.ts +5 -3
- package/src/transforms/csf-2-to-3.ts +23 -16
- 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) =>
|
11
|
-
|
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 {
|
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 }:
|
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
|
-
|
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
|
-
|
179
|
-
|
180
|
-
|
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
|
191
|
+
export const parser = 'tsx';
|
package/tsconfig.json
CHANGED