@storybook/codemod 9.0.0-alpha.1 → 9.0.0-alpha.11
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.
- package/README.md +1 -156
- package/dist/index.d.ts +0 -3
- package/dist/index.js +1 -1
- package/dist/transforms/csf-2-to-3.js +1 -1
- package/dist/transforms/find-implicit-spies.js +1 -1
- package/dist/transforms/upgrade-deprecated-types.d.ts +1 -1
- package/dist/transforms/upgrade-deprecated-types.js +1 -1
- package/package.json +2 -17
- package/dist/transforms/add-component-parameters.d.ts +0 -21
- package/dist/transforms/add-component-parameters.js +0 -1
- package/dist/transforms/csf-hoist-story-annotations.d.ts +0 -26
- package/dist/transforms/csf-hoist-story-annotations.js +0 -1
- package/dist/transforms/mdx-to-csf.d.ts +0 -10
- package/dist/transforms/mdx-to-csf.js +0 -67
- package/dist/transforms/migrate-to-test-package.d.ts +0 -6
- package/dist/transforms/migrate-to-test-package.js +0 -1
- package/dist/transforms/move-builtin-addons.d.ts +0 -3
- package/dist/transforms/move-builtin-addons.js +0 -1
- package/dist/transforms/storiesof-to-csf.d.ts +0 -25
- package/dist/transforms/storiesof-to-csf.js +0 -1
- package/dist/transforms/update-addon-info.d.ts +0 -23
- package/dist/transforms/update-addon-info.js +0 -1
- package/dist/transforms/update-organisation-name.d.ts +0 -25
- package/dist/transforms/update-organisation-name.js +0 -1
@@ -1 +0,0 @@
|
|
1
|
-
var __create=Object.create;var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __getProtoOf=Object.getPrototypeOf,__hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toESM=(mod,isNodeMode,target)=>(target=mod!=null?__create(__getProtoOf(mod)):{},__copyProps(isNodeMode||!mod||!mod.__esModule?__defProp(target,"default",{value:mod,enumerable:!0}):target,mod)),__toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var migrate_to_test_package_exports={};__export(migrate_to_test_package_exports,{default:()=>transform,parser:()=>parser});module.exports=__toCommonJS(migrate_to_test_package_exports);var import_babel=require("@storybook/core/babel"),import_csf_tools=require("@storybook/core/csf-tools"),import_prettier=__toESM(require("prettier"));async function transform(info){let csf=(0,import_csf_tools.loadCsf)(info.source,{makeTitle:title=>title}),fileNode=csf._ast;new import_babel.core.File({filename:info.path},{code:info.source,ast:fileNode}).path.traverse({ImportDeclaration:path=>{(path.node.source.value==="@storybook/jest"||path.node.source.value==="@storybook/testing-library")&&(path.node.source.value==="@storybook/jest"&&path.get("specifiers").forEach(specifier=>{if(specifier.isImportSpecifier()){let imported=specifier.get("imported");if(!imported.isIdentifier())return;imported.node.name==="jest"&&(specifier.remove(),path.insertAfter(import_babel.types.importDeclaration([import_babel.types.importNamespaceSpecifier(import_babel.types.identifier("test"))],import_babel.types.stringLiteral("@storybook/test"))))}}),path.get("source").replaceWith(import_babel.types.stringLiteral("@storybook/test")))},Identifier:path=>{path.node.name==="jest"&&path.replaceWith(import_babel.types.identifier("test"))}});let output=(0,import_csf_tools.printCsf)(csf).code;try{output=await import_prettier.default.format(output,{...await import_prettier.default.resolveConfig(info.path),filepath:info.path})}catch{console.warn(`Failed applying prettier to ${info.path}.`)}return output}var parser="tsx";0&&(module.exports={parser});
|
@@ -1 +0,0 @@
|
|
1
|
-
var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var move_builtin_addons_exports={};__export(move_builtin_addons_exports,{default:()=>transformer});module.exports=__toCommonJS(move_builtin_addons_exports);function transformer(file,api){let j=api.jscodeshift,createImportDeclaration=(specifiers,source)=>j.importDeclaration(specifiers.map(s=>j.importSpecifier(j.identifier(s))),j.literal(source)),deprecates={action:[["action"],"@storybook/addon-actions"],linkTo:[["linkTo"],"@storybook/addon-links"]};return j(file.source).find(j.ImportDeclaration).filter(i=>i.value.source.value==="@storybook/react").forEach(i=>{let importStatement=i.value;importStatement.specifiers=importStatement.specifiers.filter(specifier=>{let item=deprecates[specifier.local.name];if(item){let[specifiers,moduleName]=item;return i.insertAfter(createImportDeclaration(specifiers,moduleName)),!1}return specifier})}).toSource({quote:"single"})}
|
@@ -1,25 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Convert a legacy story API to component story format
|
3
|
-
*
|
4
|
-
* For example:
|
5
|
-
*
|
6
|
-
* ```
|
7
|
-
* input { Button } from './Button';
|
8
|
-
* storiesOf('Button', module).add('story', () => <Button label="The Button" />);
|
9
|
-
* ```
|
10
|
-
*
|
11
|
-
* Becomes:
|
12
|
-
*
|
13
|
-
* ```
|
14
|
-
* input { Button } from './Button';
|
15
|
-
* export default {
|
16
|
-
* title: 'Button'
|
17
|
-
* }
|
18
|
-
* export const story = () => <Button label="The Button" />;
|
19
|
-
*
|
20
|
-
* NOTES: only support chained storiesOf() calls
|
21
|
-
* ```
|
22
|
-
*/
|
23
|
-
declare function transformer(file: any, api: any, options: any): Promise<any>;
|
24
|
-
|
25
|
-
export { transformer as default };
|
@@ -1 +0,0 @@
|
|
1
|
-
var __create=Object.create;var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __getProtoOf=Object.getPrototypeOf,__hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toESM=(mod,isNodeMode,target)=>(target=mod!=null?__create(__getProtoOf(mod)):{},__copyProps(isNodeMode||!mod||!mod.__esModule?__defProp(target,"default",{value:mod,enumerable:!0}):target,mod)),__toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var storiesof_to_csf_exports={};__export(storiesof_to_csf_exports,{default:()=>transformer});module.exports=__toCommonJS(storiesof_to_csf_exports);var import_csf=require("@storybook/core/csf"),import_node_logger=require("@storybook/core/node-logger"),import_prettier=__toESM(require("prettier"));var import_compat=require("es-toolkit/compat"),sanitizeName=name=>{let key=(0,import_compat.upperFirst)((0,import_compat.camelCase)(name));return/^\d/.test(key)&&(key=`_${key}`),/^\d/.test(key)&&(key=`_${key}`),key};function jscodeshiftToPrettierParser(parser){let parserMap={babylon:"babel",flow:"flow",ts:"typescript",tsx:"typescript"};return parser&&parserMap[parser]||"babel"}async function transformer(file,api,options){let LITERAL=["ts","tsx"].includes(options.parser)?"StringLiteral":"Literal",j=api.jscodeshift,root=j(file.source);function extractDecorators(parameters){if(!parameters)return{};if(!parameters.properties)return{storyParams:parameters};let storyDecorators=parameters.properties.find(p=>p.key.name==="decorators");if(!storyDecorators)return{storyParams:parameters};storyDecorators=storyDecorators.value;let storyParams={...parameters};return storyParams.properties=storyParams.properties.filter(p=>p.key.name!=="decorators"),storyParams.properties.length===0?{storyDecorators}:{storyParams,storyDecorators}}function convertToModuleExports(path,originalExports2){let base=j(path),statements=[],extraExports=[],decorators=[];base.find(j.CallExpression).filter(call=>call.node.callee.property&&call.node.callee.property.name==="addDecorator").forEach(add=>{let decorator=add.node.arguments[0];decorators.push(decorator)}),decorators.length>0&&(decorators.reverse(),extraExports.push(j.property("init",j.identifier("decorators"),j.arrayExpression(decorators))));let parameters=[];base.find(j.CallExpression).filter(call=>call.node.callee.property&&call.node.callee.property.name==="addParameters").forEach(add=>{let params=[...add.node.arguments[0].properties];params.reverse(),params.forEach(prop=>parameters.push(prop))}),parameters.length>0&&(parameters.reverse(),extraExports.push(j.property("init",j.identifier("parameters"),j.objectExpression(parameters)))),originalExports2.length>0&&extraExports.push(j.property("init",j.identifier("excludeStories"),j.arrayExpression(originalExports2.map(exp=>j.literal(exp))))),base.find(j.CallExpression).filter(call=>call.node.callee.name==="storiesOf").filter(call=>call.node.arguments.length>0&&call.node.arguments[0].type===LITERAL).forEach(storiesOf=>{let title=storiesOf.node.arguments[0].value;statements.push(j.exportDefaultDeclaration(j.objectExpression([j.property("init",j.identifier("title"),j.literal(title)),...extraExports])))});let adds=[];base.find(j.CallExpression).filter(add=>add.node.callee.property&&add.node.callee.property.name==="add").filter(add=>add.node.arguments.length>=2&&add.node.arguments[0].type===LITERAL).forEach(add=>adds.push(add)),adds.reverse(),adds.push(path);let identifiers=new Set;root.find(j.Identifier).forEach(({value})=>identifiers.add(value.name)),adds.forEach(add=>{let name=add.node.arguments[0].value,key=sanitizeName(name);for(;identifiers.has(key);)key=`_${key}`;identifiers.add(key),(0,import_csf.storyNameFromExport)(key)===name&&(name=null);let val=add.node.arguments[1];statements.push(j.exportDeclaration(!1,j.variableDeclaration("const",[j.variableDeclarator(j.identifier(key),val)])));let storyAnnotations=[];if(name&&storyAnnotations.push(j.property("init",j.identifier("name"),j.literal(name))),add.node.arguments.length>2){let originalStoryParams=add.node.arguments[2],{storyParams,storyDecorators}=extractDecorators(originalStoryParams);storyParams&&storyAnnotations.push(j.property("init",j.identifier("parameters"),storyParams)),storyDecorators&&storyAnnotations.push(j.property("init",j.identifier("decorators"),storyDecorators))}storyAnnotations.length>0&&statements.push(j.assignmentStatement("=",j.memberExpression(j.identifier(key),j.identifier("story")),j.objectExpression(storyAnnotations)))});let stmt=path.parent.node.type==="VariableDeclarator"?path.parent.parent:path.parent;statements.reverse(),statements.forEach(s=>stmt.insertAfter(s)),j(stmt).remove()}let initialStoriesOf=root.find(j.CallExpression).filter(call=>call.node.callee.name==="storiesOf");if(root.find(j.ExportDefaultDeclaration).size()>0)return initialStoriesOf.size()>0&&import_node_logger.logger.warn(`Found ${initialStoriesOf.size()} 'storiesOf' calls but existing default export, SKIPPING: '${file.path}'`),root.toSource();let originalExports=[];root.find(j.ExportNamedDeclaration).forEach(exp=>{let{declaration,specifiers}=exp.node;if(declaration){let{id,declarations}=declaration;declarations?declarations.forEach(decl=>{let{name,properties}=decl.id;name?originalExports.push(name):properties&&properties.forEach(prop=>originalExports.push(prop.key.name))}):id&&originalExports.push(id.name)}else specifiers&&specifiers.forEach(spec=>originalExports.push(spec.exported.name))}),root.find(j.CallExpression).filter(add=>add.node.callee.property&&add.node.callee.property.name==="add").filter(add=>add.node.arguments.length>=2&&add.node.arguments[0].type===LITERAL).filter(add=>["ExpressionStatement","VariableDeclarator"].includes(add.parentPath.node.type)).forEach(path=>convertToModuleExports(path,originalExports)),root.find(j.ImportSpecifier).filter(spec=>spec.node.imported.name==="storiesOf"&&spec.parent.node.source.value.startsWith("@storybook/")).forEach(spec=>{let toRemove=spec.parent.node.specifiers.length>1?spec:spec.parent;j(toRemove).remove()});let source=root.toSource({trailingComma:!0,quote:"single",tabWidth:2});if(initialStoriesOf.size()>1)return import_node_logger.logger.warn(`Found ${initialStoriesOf.size()} 'storiesOf' calls, PLEASE FIX BY HAND: '${file.path}'`),source;let output=source;try{let prettierConfig=await import_prettier.default.resolveConfig(file.path);output=import_prettier.default.format(source,{...prettierConfig,parser:jscodeshiftToPrettierParser(options.parser)})}catch{import_node_logger.logger.warn(`Failed to format ${file.path} with prettier`)}return output}
|
@@ -1,23 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Takes the deprecated addon-info API, addWithInfo, and converts to the new withInfo API.
|
3
|
-
*
|
4
|
-
* @example Of deprecated addWithInfo API:
|
5
|
-
*
|
6
|
-
* ```jsx
|
7
|
-
* storiesOf('Button').addWithInfo('story name', 'Story description.', () => (
|
8
|
-
* <Button label="The Button" />
|
9
|
-
* ));
|
10
|
-
* ```
|
11
|
-
*
|
12
|
-
* Converts to the new withInfo API:
|
13
|
-
*
|
14
|
-
* ```jsx
|
15
|
-
* storiesOf('Button').add(
|
16
|
-
* 'story name',
|
17
|
-
* withInfo('Story description.')(() => <Button label="The Button" />)
|
18
|
-
* );
|
19
|
-
* ```
|
20
|
-
*/
|
21
|
-
declare function transformer(file: any, api: any): any;
|
22
|
-
|
23
|
-
export { transformer as default };
|
@@ -1 +0,0 @@
|
|
1
|
-
var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var update_addon_info_exports={};__export(update_addon_info_exports,{default:()=>transformer});module.exports=__toCommonJS(update_addon_info_exports);function transformer(file,api){let j=api.jscodeshift,root=j(file.source),getOptions=args=>args[3]===void 0?args[2]===void 0?[args[0]]:[args[1]]:[j.objectExpression([j.property("init",j.identifier("text"),args[1]),...args[3].properties])],withInfo=addWithInfoExpression=>{let{node}=addWithInfoExpression,args=node.arguments,storyComponent=args[2]?args[2]:args[1];return node.callee.property.name="add",node.arguments=[args[0],j.callExpression(j.callExpression(j.identifier("withInfo"),getOptions(args)),[storyComponent])],node},checkWithInfoImport=()=>{root.find(j.ImportDeclaration).filter(imp=>imp.node.source.value==="@storybook/addon-info").size()||root.find(j.ImportDeclaration).at(-1).insertAfter(j.importDeclaration([j.importSpecifier(j.identifier("withInfo"))],j.literal("@storybook/addon-info")))},addWithInfoExpressions=root.find(j.CallExpression,{callee:{property:{name:"addWithInfo"}}});return addWithInfoExpressions.size()&&(checkWithInfoImport(),addWithInfoExpressions.replaceWith(withInfo)),root.toSource()}
|
@@ -1,25 +0,0 @@
|
|
1
|
-
declare function transformer(file: any, api: any): any;
|
2
|
-
declare const packageNames: {
|
3
|
-
'@kadira/react-storybook-decorator-centered': string;
|
4
|
-
'@kadira/storybook-addons': string;
|
5
|
-
'@kadira/storybook-addon-actions': string;
|
6
|
-
'@kadira/storybook-addon-comments': string;
|
7
|
-
'@kadira/storybook-addon-graphql': string;
|
8
|
-
'@kadira/storybook-addon-info': string;
|
9
|
-
'@kadira/storybook-addon-knobs': string;
|
10
|
-
'@kadira/storybook-addon-links': string;
|
11
|
-
'@kadira/storybook-addon-notes': string;
|
12
|
-
'@kadira/storybook-addon-options': string;
|
13
|
-
'@kadira/storybook-channels': string;
|
14
|
-
'@kadira/storybook-channel-postmsg': string;
|
15
|
-
'@kadira/storybook-channel-websocket': string;
|
16
|
-
'@kadira/storybook-ui': string;
|
17
|
-
'@kadira/react-native-storybook': string;
|
18
|
-
'@kadira/react-storybook': string;
|
19
|
-
'@kadira/getstorybook': string;
|
20
|
-
'@kadira/storybook': string;
|
21
|
-
storyshots: string;
|
22
|
-
getstorybook: string;
|
23
|
-
};
|
24
|
-
|
25
|
-
export { transformer as default, packageNames };
|
@@ -1 +0,0 @@
|
|
1
|
-
var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var update_organisation_name_exports={};__export(update_organisation_name_exports,{default:()=>transformer,packageNames:()=>packageNames});module.exports=__toCommonJS(update_organisation_name_exports);var packageNames={"@kadira/react-storybook-decorator-centered":"@storybook/addon-centered","@kadira/storybook-addons":"storybook/internal/preview-api","@kadira/storybook-addon-actions":"@storybook/addon-actions","@kadira/storybook-addon-comments":"@storybook/addon-comments","@kadira/storybook-addon-graphql":"@storybook/addon-graphql","@kadira/storybook-addon-info":"@storybook/addon-info","@kadira/storybook-addon-knobs":"@storybook/addon-knobs","@kadira/storybook-addon-links":"@storybook/addon-links","@kadira/storybook-addon-notes":"@storybook/addon-notes","@kadira/storybook-addon-options":"@storybook/addon-options","@kadira/storybook-channels":"storybook/internal/channels","@kadira/storybook-channel-postmsg":"@storybook/channel-postmessage","@kadira/storybook-channel-websocket":"@storybook/channel-websocket","@kadira/storybook-ui":"storybook/internal/manager","@kadira/react-native-storybook":"@storybook/react-native","@kadira/react-storybook":"@storybook/react","@kadira/getstorybook":"storybook","@kadira/storybook":"@storybook/react",storyshots:"@storybook/addon-storyshots",getstorybook:"storybook"};function transformer(file,api){let j=api.jscodeshift,packageNamesKeys=Object.keys(packageNames),getMatch=oldpart=>packageNamesKeys.find(newpart=>oldpart.match(newpart)),getNewPackageName=oldPackageName=>{let match=getMatch(oldPackageName);if(match){let replacement=packageNames[match];return oldPackageName.replace(match,replacement)}return oldPackageName},updatePackageName=declaration=>(declaration.node.source.value=getNewPackageName(declaration.node.source.value),declaration.node);return j(file.source).find(j.ImportDeclaration).replaceWith(updatePackageName).toSource({quote:"single"})}0&&(module.exports={packageNames});
|