@storybook/codemod 0.0.0-pr-23479-sha-bcda497a → 0.0.0-pr-23882-sha-6c4dd3dd

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 (97) hide show
  1. package/dist/transforms/csf-2-to-3.js +2 -2
  2. package/dist/transforms/upgrade-deprecated-types.js +1 -1
  3. package/package.json +14 -7
  4. package/project.json +0 -6
  5. package/src/index.ts +0 -103
  6. package/src/lib/utils.test.js +0 -9
  7. package/src/lib/utils.ts +0 -29
  8. package/src/transforms/__testfixtures__/add-component-parameters/add-component-parameters.input.js +0 -44
  9. package/src/transforms/__testfixtures__/add-component-parameters/add-component-parameters.output.snapshot +0 -68
  10. package/src/transforms/__testfixtures__/csf-hoist-story-annotations/basic.input.js +0 -25
  11. package/src/transforms/__testfixtures__/csf-hoist-story-annotations/basic.output.snapshot +0 -27
  12. package/src/transforms/__testfixtures__/csf-hoist-story-annotations/overrides.input.js +0 -25
  13. package/src/transforms/__testfixtures__/csf-hoist-story-annotations/overrides.output.snapshot +0 -28
  14. package/src/transforms/__testfixtures__/csf-hoist-story-annotations/variable.input.js +0 -13
  15. package/src/transforms/__testfixtures__/csf-hoist-story-annotations/variable.output.snapshot +0 -17
  16. package/src/transforms/__testfixtures__/mdx-to-csf/basic.input.mdx +0 -18
  17. package/src/transforms/__testfixtures__/mdx-to-csf/basic.output.snapshot +0 -40
  18. package/src/transforms/__testfixtures__/mdx-to-csf/component-id.input.mdx +0 -6
  19. package/src/transforms/__testfixtures__/mdx-to-csf/component-id.output.snapshot +0 -17
  20. package/src/transforms/__testfixtures__/mdx-to-csf/decorators.input.mdx +0 -8
  21. package/src/transforms/__testfixtures__/mdx-to-csf/decorators.output.snapshot +0 -18
  22. package/src/transforms/__testfixtures__/mdx-to-csf/exclude-stories.input.mdx +0 -19
  23. package/src/transforms/__testfixtures__/mdx-to-csf/exclude-stories.output.snapshot +0 -39
  24. package/src/transforms/__testfixtures__/mdx-to-csf/parameters.input.mdx +0 -14
  25. package/src/transforms/__testfixtures__/mdx-to-csf/parameters.output.snapshot +0 -23
  26. package/src/transforms/__testfixtures__/mdx-to-csf/plaintext.input.mdx +0 -3
  27. package/src/transforms/__testfixtures__/mdx-to-csf/plaintext.output.snapshot +0 -11
  28. package/src/transforms/__testfixtures__/mdx-to-csf/story-function.input.mdx +0 -10
  29. package/src/transforms/__testfixtures__/mdx-to-csf/story-function.output.snapshot +0 -18
  30. package/src/transforms/__testfixtures__/mdx-to-csf/story-parameters.input.mdx +0 -18
  31. package/src/transforms/__testfixtures__/mdx-to-csf/story-parameters.output.snapshot +0 -32
  32. package/src/transforms/__testfixtures__/mdx-to-csf/story-refs.input.mdx +0 -22
  33. package/src/transforms/__testfixtures__/mdx-to-csf/story-refs.output.snapshot +0 -34
  34. package/src/transforms/__testfixtures__/move-builtin-addons/default.input.js +0 -2
  35. package/src/transforms/__testfixtures__/move-builtin-addons/default.output.snapshot +0 -8
  36. package/src/transforms/__testfixtures__/move-builtin-addons/with-no-change.input.js +0 -3
  37. package/src/transforms/__testfixtures__/move-builtin-addons/with-no-change.output.snapshot +0 -7
  38. package/src/transforms/__testfixtures__/storiesof-to-csf/basic.input.js +0 -18
  39. package/src/transforms/__testfixtures__/storiesof-to-csf/basic.output.snapshot +0 -45
  40. package/src/transforms/__testfixtures__/storiesof-to-csf/collision.input.js +0 -11
  41. package/src/transforms/__testfixtures__/storiesof-to-csf/collision.output.snapshot +0 -38
  42. package/src/transforms/__testfixtures__/storiesof-to-csf/const.input.js +0 -1
  43. package/src/transforms/__testfixtures__/storiesof-to-csf/const.output.snapshot +0 -13
  44. package/src/transforms/__testfixtures__/storiesof-to-csf/decorators.input.js +0 -9
  45. package/src/transforms/__testfixtures__/storiesof-to-csf/decorators.output.snapshot +0 -18
  46. package/src/transforms/__testfixtures__/storiesof-to-csf/default.input.js +0 -7
  47. package/src/transforms/__testfixtures__/storiesof-to-csf/default.output.snapshot +0 -17
  48. package/src/transforms/__testfixtures__/storiesof-to-csf/digit.input.js +0 -1
  49. package/src/transforms/__testfixtures__/storiesof-to-csf/digit.output.js +0 -5
  50. package/src/transforms/__testfixtures__/storiesof-to-csf/digit.output.snapshot +0 -9
  51. package/src/transforms/__testfixtures__/storiesof-to-csf/export-destructuring.input.js +0 -11
  52. package/src/transforms/__testfixtures__/storiesof-to-csf/export-destructuring.output.snapshot +0 -23
  53. package/src/transforms/__testfixtures__/storiesof-to-csf/export-function.input.js +0 -12
  54. package/src/transforms/__testfixtures__/storiesof-to-csf/export-function.output.snapshot +0 -23
  55. package/src/transforms/__testfixtures__/storiesof-to-csf/export-names.input.js +0 -14
  56. package/src/transforms/__testfixtures__/storiesof-to-csf/export-names.output.snapshot +0 -26
  57. package/src/transforms/__testfixtures__/storiesof-to-csf/exports.input.js +0 -2
  58. package/src/transforms/__testfixtures__/storiesof-to-csf/exports.output.snapshot +0 -16
  59. package/src/transforms/__testfixtures__/storiesof-to-csf/module.input.js +0 -12
  60. package/src/transforms/__testfixtures__/storiesof-to-csf/module.output.snapshot +0 -16
  61. package/src/transforms/__testfixtures__/storiesof-to-csf/multi.input.js +0 -14
  62. package/src/transforms/__testfixtures__/storiesof-to-csf/multi.output.snapshot +0 -39
  63. package/src/transforms/__testfixtures__/storiesof-to-csf/parameters-as-var.input.js +0 -8
  64. package/src/transforms/__testfixtures__/storiesof-to-csf/parameters-as-var.output.snapshot +0 -20
  65. package/src/transforms/__testfixtures__/storiesof-to-csf/parameters.input.js +0 -10
  66. package/src/transforms/__testfixtures__/storiesof-to-csf/parameters.output.snapshot +0 -23
  67. package/src/transforms/__testfixtures__/storiesof-to-csf/storiesof-var.input.js +0 -11
  68. package/src/transforms/__testfixtures__/storiesof-to-csf/storiesof-var.output.snapshot +0 -23
  69. package/src/transforms/__testfixtures__/storiesof-to-csf/story-decorators.input.js +0 -11
  70. package/src/transforms/__testfixtures__/storiesof-to-csf/story-decorators.output.snapshot +0 -29
  71. package/src/transforms/__testfixtures__/storiesof-to-csf/story-parameters.input.js +0 -14
  72. package/src/transforms/__testfixtures__/storiesof-to-csf/story-parameters.output.snapshot +0 -32
  73. package/src/transforms/__testfixtures__/update-addon-info/update-addon-info.input.js +0 -184
  74. package/src/transforms/__testfixtures__/update-addon-info/update-addon-info.output.snapshot +0 -184
  75. package/src/transforms/__testfixtures__/update-organisation-name/update-organisation-name.input.js +0 -19
  76. package/src/transforms/__testfixtures__/update-organisation-name/update-organisation-name.output.snapshot +0 -23
  77. package/src/transforms/__testfixtures__/upgrade-hierarchy-separators/csf.input.js +0 -3
  78. package/src/transforms/__testfixtures__/upgrade-hierarchy-separators/csf.output.snapshot +0 -7
  79. package/src/transforms/__testfixtures__/upgrade-hierarchy-separators/dynamic-storiesof.input.js +0 -5
  80. package/src/transforms/__testfixtures__/upgrade-hierarchy-separators/dynamic-storiesof.output.snapshot +0 -9
  81. package/src/transforms/__testfixtures__/upgrade-hierarchy-separators/storiesof.input.js +0 -8
  82. package/src/transforms/__testfixtures__/upgrade-hierarchy-separators/storiesof.output.snapshot +0 -12
  83. package/src/transforms/__tests__/csf-2-to-3.test.ts +0 -439
  84. package/src/transforms/__tests__/mdx-to-csf.test.ts +0 -628
  85. package/src/transforms/__tests__/transforms.tests.js +0 -32
  86. package/src/transforms/__tests__/upgrade-deprecated-types.test.ts +0 -170
  87. package/src/transforms/add-component-parameters.js +0 -62
  88. package/src/transforms/csf-2-to-3.ts +0 -336
  89. package/src/transforms/csf-hoist-story-annotations.js +0 -97
  90. package/src/transforms/mdx-to-csf.ts +0 -340
  91. package/src/transforms/move-builtin-addons.js +0 -32
  92. package/src/transforms/storiesof-to-csf.js +0 -277
  93. package/src/transforms/update-addon-info.js +0 -114
  94. package/src/transforms/update-organisation-name.js +0 -71
  95. package/src/transforms/upgrade-deprecated-types.ts +0 -142
  96. package/src/transforms/upgrade-hierarchy-separators.js +0 -39
  97. package/tsconfig.json +0 -10
@@ -1,3 +1,3 @@
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 csf_2_to_3_exports={};__export(csf_2_to_3_exports,{default:()=>transform,parser:()=>parser});module.exports=__toCommonJS(csf_2_to_3_exports);var import_prettier2=__toESM(require("prettier")),t2=__toESM(require("@babel/types")),import_types=require("@babel/types"),import_csf_tools2=require("@storybook/csf-tools"),babel2=__toESM(require("@babel/core")),recast2=__toESM(require("recast"));var import_prettier=__toESM(require("prettier")),babel=__toESM(require("@babel/core")),import_csf_tools=require("@storybook/csf-tools"),recast=__toESM(require("recast")),t=__toESM(require("@babel/types"));var deprecatedTypes=["ComponentStory","ComponentStoryFn","ComponentStoryObj","ComponentMeta","Story"];function migrateType(oldType){return oldType==="Story"||oldType==="ComponentStory"?"StoryFn":oldType.replace("Component","")}function upgradeDeprecatedTypes(file){let importedNamespaces=new Set,typeReferencesToUpdate=new Set,existingImports=[];file.path.traverse({ImportDeclaration:path=>{existingImports.push(...path.get("specifiers").map(specifier=>({name:specifier.node.local.name,isAlias:!(specifier.isImportSpecifier()&&t.isIdentifier(specifier.node.imported)&&specifier.node.local.name===specifier.node.imported.name),path:specifier}))),path.node.source.value.startsWith("@storybook")&&path.get("specifiers").forEach(specifier=>{if(specifier.isImportNamespaceSpecifier()&&importedNamespaces.add(specifier.node.local.name),!specifier.isImportSpecifier())return;let imported=specifier.get("imported");if(imported.isIdentifier()&&deprecatedTypes.includes(imported.node.name)){imported.node.name===specifier.node.local.name&&typeReferencesToUpdate.add(specifier.node.local.name);let newType=migrateType(imported.node.name);if(!existingImports.some(it=>it.name===newType))imported.replaceWith(t.identifier(newType)),existingImports.push({name:newType,isAlias:!1,path:specifier});else{let existingImport=existingImports.find(it=>it.name===newType&&it.isAlias);if(existingImport)throw existingImport.path.buildCodeFrameError(`This codemod does not support local imports that are called the same as a storybook import.
2
- Rename this local import and try again.`);specifier.remove()}}})}}),file.path.traverse({TSTypeReference:path=>{let typeName=path.get("typeName");if(typeName.isIdentifier())typeReferencesToUpdate.has(typeName.node.name)&&typeName.replaceWith(t.identifier(migrateType(typeName.node.name)));else if(typeName.isTSQualifiedName()){let namespace=typeName.get("left");if(namespace.isIdentifier()&&importedNamespaces.has(namespace.node.name)){let right=typeName.get("right");deprecatedTypes.includes(right.node.name)&&right.replaceWith(t.identifier(migrateType(right.node.name)))}}}})}var logger=console,renameAnnotation=annotation=>annotation==="storyName"?"name":annotation,getTemplateBindVariable=init=>t2.isCallExpression(init)&&t2.isMemberExpression(init.callee)&&t2.isIdentifier(init.callee.object)&&t2.isIdentifier(init.callee.property)&&init.callee.property.name==="bind"&&(init.arguments.length===0||init.arguments.length===1&&t2.isObjectExpression(init.arguments[0])&&init.arguments[0].properties.length===0)?init.callee.object.name:null,isStoryAnnotation=(stmt,objectExports)=>t2.isExpressionStatement(stmt)&&t2.isAssignmentExpression(stmt.expression)&&t2.isMemberExpression(stmt.expression.left)&&t2.isIdentifier(stmt.expression.left.object)&&objectExports[stmt.expression.left.object.name],getNewExport=(stmt,objectExports)=>{if(t2.isExportNamedDeclaration(stmt)&&t2.isVariableDeclaration(stmt.declaration)&&stmt.declaration.declarations.length===1){let decl=stmt.declaration.declarations[0];if(t2.isVariableDeclarator(decl)&&t2.isIdentifier(decl.id))return objectExports[decl.id.name]}return null},isReactGlobalRenderFn=(csf,storyFn)=>{var _a;if((_a=csf._meta)!=null&&_a.component&&t2.isArrowFunctionExpression(storyFn)&&storyFn.params.length===1&&t2.isJSXElement(storyFn.body)){let{openingElement}=storyFn.body;if(openingElement.selfClosing&&t2.isJSXIdentifier(openingElement.name)&&openingElement.attributes.length===1){let attr=openingElement.attributes[0],param=storyFn.params[0];if(t2.isJSXSpreadAttribute(attr)&&t2.isIdentifier(attr.argument)&&t2.isIdentifier(param)&&param.name===attr.argument.name&&csf._meta.component===openingElement.name.name)return!0}}return!1},isSimpleCSFStory=(init,annotations)=>annotations.length===0&&t2.isArrowFunctionExpression(init)&&init.params.length===0;function removeUnusedTemplates(csf){Object.entries(csf._templates).forEach(([template,templateExpression])=>{let references=[];if(babel2.traverse(csf._ast,{Identifier:path=>{path.node.name===template&&references.push(path)}}),references.length===1){let reference=references[0];reference.parentPath.isVariableDeclarator()&&reference.parentPath.node.init===templateExpression&&reference.parentPath.remove()}})}function transform(info,api,options){let makeTitle=userTitle=>userTitle||"FIXME",csf=(0,import_csf_tools2.loadCsf)(info.source,{makeTitle});try{csf.parse()}catch(err){return logger.log(`Error ${err}, skipping`),info.source}let file=new babel2.File({filename:info.path},{code:info.source,ast:csf._ast}),importHelper=new StorybookImportHelper(file,info),objectExports={};Object.entries(csf._storyExports).forEach(([key,decl])=>{let annotations=Object.entries(csf._storyAnnotations[key]).map(([annotation,val])=>t2.objectProperty(t2.identifier(renameAnnotation(annotation)),val));if(t2.isVariableDeclarator(decl)){let{init,id}=decl,template=getTemplateBindVariable(init);if(!t2.isArrowFunctionExpression(init)&&!template)return;if(isSimpleCSFStory(init,annotations)){objectExports[key]=t2.exportNamedDeclaration(t2.variableDeclaration("const",[t2.variableDeclarator(importHelper.updateTypeTo(id,"StoryFn"),init)]));return}let storyFn=template&&t2.identifier(template);storyFn||(storyFn=init);let renderAnnotation=isReactGlobalRenderFn(csf,template?csf._templates[template]:storyFn)?[]:[t2.objectProperty(t2.identifier("render"),storyFn)];objectExports[key]=t2.exportNamedDeclaration(t2.variableDeclaration("const",[t2.variableDeclarator(importHelper.updateTypeTo(id,"StoryObj"),t2.objectExpression([...renderAnnotation,...annotations]))]))}}),csf._ast.program.body=csf._ast.program.body.reduce((acc,stmt)=>{let statement=stmt;if(isStoryAnnotation(statement,objectExports))return acc;let newExport=getNewExport(statement,objectExports);return newExport?(acc.push(newExport),acc):(acc.push(statement),acc)},[]),upgradeDeprecatedTypes(file),importHelper.removeDeprecatedStoryImport(),removeUnusedTemplates(csf);let output=recast2.print(csf._ast,{}).code;try{let prettierConfig=import_prettier2.default.resolveConfig.sync(".",{editorconfig:!0})||{printWidth:100,tabWidth:2,bracketSpacing:!0,trailingComma:"es5",singleQuote:!0};output=import_prettier2.default.format(output,{...prettierConfig,filepath:info.path})}catch{logger.log(`Failed applying prettier to ${info.path}.`)}return output}var StorybookImportHelper=class{constructor(file,info){this.getAllSbImportDeclarations=file=>{let found=[];return file.path.traverse({ImportDeclaration:path=>{let source=path.node.source.value;if(source.startsWith("@storybook/csf")||!source.startsWith("@storybook"))return;path.get("specifiers").some(specifier=>{if(specifier.isImportNamespaceSpecifier())throw new Error(`This codemod does not support namespace imports for a ${path.node.source.value} package.
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 csf_2_to_3_exports={};__export(csf_2_to_3_exports,{default:()=>transform,parser:()=>parser});module.exports=__toCommonJS(csf_2_to_3_exports);var import_prettier2=__toESM(require("prettier")),t2=__toESM(require("@babel/types")),import_types=require("@babel/types"),import_csf_tools2=require("@storybook/csf-tools"),babel2=__toESM(require("@babel/core"));var import_prettier=__toESM(require("prettier")),babel=__toESM(require("@babel/core")),import_csf_tools=require("@storybook/csf-tools"),t=__toESM(require("@babel/types"));var deprecatedTypes=["ComponentStory","ComponentStoryFn","ComponentStoryObj","ComponentMeta","Story"];function migrateType(oldType){return oldType==="Story"||oldType==="ComponentStory"?"StoryFn":oldType.replace("Component","")}function upgradeDeprecatedTypes(file){let importedNamespaces=new Set,typeReferencesToUpdate=new Set,existingImports=[];file.path.traverse({ImportDeclaration:path=>{existingImports.push(...path.get("specifiers").map(specifier=>({name:specifier.node.local.name,isAlias:!(specifier.isImportSpecifier()&&t.isIdentifier(specifier.node.imported)&&specifier.node.local.name===specifier.node.imported.name),path:specifier}))),path.node.source.value.startsWith("@storybook")&&path.get("specifiers").forEach(specifier=>{if(specifier.isImportNamespaceSpecifier()&&importedNamespaces.add(specifier.node.local.name),!specifier.isImportSpecifier())return;let imported=specifier.get("imported");if(imported.isIdentifier()&&deprecatedTypes.includes(imported.node.name)){imported.node.name===specifier.node.local.name&&typeReferencesToUpdate.add(specifier.node.local.name);let newType=migrateType(imported.node.name);if(!existingImports.some(it=>it.name===newType))imported.replaceWith(t.identifier(newType)),existingImports.push({name:newType,isAlias:!1,path:specifier});else{let existingImport=existingImports.find(it=>it.name===newType&&it.isAlias);if(existingImport)throw existingImport.path.buildCodeFrameError(`This codemod does not support local imports that are called the same as a storybook import.
2
+ Rename this local import and try again.`);specifier.remove()}}})}}),file.path.traverse({TSTypeReference:path=>{let typeName=path.get("typeName");if(typeName.isIdentifier())typeReferencesToUpdate.has(typeName.node.name)&&typeName.replaceWith(t.identifier(migrateType(typeName.node.name)));else if(typeName.isTSQualifiedName()){let namespace=typeName.get("left");if(namespace.isIdentifier()&&importedNamespaces.has(namespace.node.name)){let right=typeName.get("right");deprecatedTypes.includes(right.node.name)&&right.replaceWith(t.identifier(migrateType(right.node.name)))}}}})}var logger=console,renameAnnotation=annotation=>annotation==="storyName"?"name":annotation,getTemplateBindVariable=init=>t2.isCallExpression(init)&&t2.isMemberExpression(init.callee)&&t2.isIdentifier(init.callee.object)&&t2.isIdentifier(init.callee.property)&&init.callee.property.name==="bind"&&(init.arguments.length===0||init.arguments.length===1&&t2.isObjectExpression(init.arguments[0])&&init.arguments[0].properties.length===0)?init.callee.object.name:null,isStoryAnnotation=(stmt,objectExports)=>t2.isExpressionStatement(stmt)&&t2.isAssignmentExpression(stmt.expression)&&t2.isMemberExpression(stmt.expression.left)&&t2.isIdentifier(stmt.expression.left.object)&&objectExports[stmt.expression.left.object.name],getNewExport=(stmt,objectExports)=>{if(t2.isExportNamedDeclaration(stmt)&&t2.isVariableDeclaration(stmt.declaration)&&stmt.declaration.declarations.length===1){let decl=stmt.declaration.declarations[0];if(t2.isVariableDeclarator(decl)&&t2.isIdentifier(decl.id))return objectExports[decl.id.name]}return null},isReactGlobalRenderFn=(csf,storyFn)=>{var _a;if((_a=csf._meta)!=null&&_a.component&&t2.isArrowFunctionExpression(storyFn)&&storyFn.params.length===1&&t2.isJSXElement(storyFn.body)){let{openingElement}=storyFn.body;if(openingElement.selfClosing&&t2.isJSXIdentifier(openingElement.name)&&openingElement.attributes.length===1){let attr=openingElement.attributes[0],param=storyFn.params[0];if(t2.isJSXSpreadAttribute(attr)&&t2.isIdentifier(attr.argument)&&t2.isIdentifier(param)&&param.name===attr.argument.name&&csf._meta.component===openingElement.name.name)return!0}}return!1},isSimpleCSFStory=(init,annotations)=>annotations.length===0&&t2.isArrowFunctionExpression(init)&&init.params.length===0;function removeUnusedTemplates(csf){Object.entries(csf._templates).forEach(([template,templateExpression])=>{let references=[];if(babel2.traverse(csf._ast,{Identifier:path=>{path.node.name===template&&references.push(path)}}),references.length===1){let reference=references[0];reference.parentPath.isVariableDeclarator()&&reference.parentPath.node.init===templateExpression&&reference.parentPath.remove()}})}function transform(info,api,options){let makeTitle=userTitle=>userTitle||"FIXME",csf=(0,import_csf_tools2.loadCsf)(info.source,{makeTitle});try{csf.parse()}catch(err){return logger.log(`Error ${err}, skipping`),info.source}let file=new babel2.File({filename:info.path},{code:info.source,ast:csf._ast}),importHelper=new StorybookImportHelper(file,info),objectExports={};Object.entries(csf._storyExports).forEach(([key,decl])=>{let annotations=Object.entries(csf._storyAnnotations[key]).map(([annotation,val])=>t2.objectProperty(t2.identifier(renameAnnotation(annotation)),val));if(t2.isVariableDeclarator(decl)){let{init,id}=decl,template=getTemplateBindVariable(init);if(!t2.isArrowFunctionExpression(init)&&!template)return;if(isSimpleCSFStory(init,annotations)){objectExports[key]=t2.exportNamedDeclaration(t2.variableDeclaration("const",[t2.variableDeclarator(importHelper.updateTypeTo(id,"StoryFn"),init)]));return}let storyFn=template&&t2.identifier(template);storyFn||(storyFn=init);let renderAnnotation=isReactGlobalRenderFn(csf,template?csf._templates[template]:storyFn)?[]:[t2.objectProperty(t2.identifier("render"),storyFn)];objectExports[key]=t2.exportNamedDeclaration(t2.variableDeclaration("const",[t2.variableDeclarator(importHelper.updateTypeTo(id,"StoryObj"),t2.objectExpression([...renderAnnotation,...annotations]))]))}}),csf._ast.program.body=csf._ast.program.body.reduce((acc,stmt)=>{let statement=stmt;if(isStoryAnnotation(statement,objectExports))return acc;let newExport=getNewExport(statement,objectExports);return newExport?(acc.push(newExport),acc):(acc.push(statement),acc)},[]),upgradeDeprecatedTypes(file),importHelper.removeDeprecatedStoryImport(),removeUnusedTemplates(csf);let output=(0,import_csf_tools2.printCsf)(csf).code;try{let prettierConfig=import_prettier2.default.resolveConfig.sync(".",{editorconfig:!0})||{printWidth:100,tabWidth:2,bracketSpacing:!0,trailingComma:"es5",singleQuote:!0};output=import_prettier2.default.format(output,{...prettierConfig,filepath:info.path})}catch{logger.log(`Failed applying prettier to ${info.path}.`)}return output}var StorybookImportHelper=class{constructor(file,info){this.getAllSbImportDeclarations=file=>{let found=[];return file.path.traverse({ImportDeclaration:path=>{let source=path.node.source.value;if(source.startsWith("@storybook/csf")||!source.startsWith("@storybook"))return;path.get("specifiers").some(specifier=>{if(specifier.isImportNamespaceSpecifier())throw new Error(`This codemod does not support namespace imports for a ${path.node.source.value} package.
3
3
  Replace the namespace import with named imports and try again.`);if(!specifier.isImportSpecifier())return!1;let imported=specifier.get("imported");return imported.isIdentifier()?["Story","StoryFn","StoryObj","Meta","ComponentStory","ComponentStoryFn","ComponentStoryObj","ComponentMeta"].includes(imported.node.name):!1})&&found.push(path)}}),found};this.getOrAddImport=type=>{let sbImport=this.sbImportDeclarations.find(path=>path.node.importKind==="type")??this.sbImportDeclarations[0];if(sbImport==null)return;let specifiers=sbImport.get("specifiers"),importSpecifier2=specifiers.find(specifier=>{if(!specifier.isImportSpecifier())return!1;let imported=specifier.get("imported");return imported.isIdentifier()?imported.node.name===type:!1});return importSpecifier2?importSpecifier2.node.local.name:(specifiers[0].insertBefore(t2.importSpecifier(t2.identifier(type),t2.identifier(type))),type)};this.removeDeprecatedStoryImport=()=>{this.sbImportDeclarations.flatMap(it=>it.get("specifiers")).filter(specifier=>{if(!specifier.isImportSpecifier())return!1;let imported=specifier.get("imported");return imported.isIdentifier()?imported.node.name==="Story":!1}).forEach(path=>path.remove())};this.getAllLocalImports=()=>this.sbImportDeclarations.flatMap(it=>it.get("specifiers")).map(it=>it.node.local.name);this.updateTypeTo=(id,type)=>{if((0,import_types.isIdentifier)(id)&&(0,import_types.isTSTypeAnnotation)(id.typeAnnotation)&&(0,import_types.isTSTypeReference)(id.typeAnnotation.typeAnnotation)&&(0,import_types.isIdentifier)(id.typeAnnotation.typeAnnotation.typeName)){let{name}=id.typeAnnotation.typeAnnotation.typeName;if(this.getAllLocalImports().includes(name)){let localTypeImport=this.getOrAddImport(type);return{...id,typeAnnotation:t2.tsTypeAnnotation(t2.tsTypeReference(t2.identifier(localTypeImport),id.typeAnnotation.typeAnnotation.typeParameters))}}}return id};this.sbImportDeclarations=this.getAllSbImportDeclarations(file)}},parser="tsx";0&&(module.exports={parser});
@@ -1,2 +1,2 @@
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 upgrade_deprecated_types_exports={};__export(upgrade_deprecated_types_exports,{default:()=>transform,parser:()=>parser,upgradeDeprecatedTypes:()=>upgradeDeprecatedTypes});module.exports=__toCommonJS(upgrade_deprecated_types_exports);var import_prettier=__toESM(require("prettier")),babel=__toESM(require("@babel/core")),import_csf_tools=require("@storybook/csf-tools"),recast=__toESM(require("recast")),t=__toESM(require("@babel/types")),logger=console,deprecatedTypes=["ComponentStory","ComponentStoryFn","ComponentStoryObj","ComponentMeta","Story"];function migrateType(oldType){return oldType==="Story"||oldType==="ComponentStory"?"StoryFn":oldType.replace("Component","")}function transform(info,api,options){let fileNode=(0,import_csf_tools.loadCsf)(info.source,{makeTitle:title=>title})._ast,file=new babel.File({filename:info.path},{code:info.source,ast:fileNode});upgradeDeprecatedTypes(file);let output=recast.print(file.path.node).code;try{let prettierConfig=import_prettier.default.resolveConfig.sync(".",{editorconfig:!0})||{printWidth:100,tabWidth:2,bracketSpacing:!0,trailingComma:"es5",singleQuote:!0};output=import_prettier.default.format(output,{...prettierConfig,filepath:info.path})}catch{logger.log(`Failed applying prettier to ${info.path}.`)}return output}var parser="tsx";function upgradeDeprecatedTypes(file){let importedNamespaces=new Set,typeReferencesToUpdate=new Set,existingImports=[];file.path.traverse({ImportDeclaration:path=>{existingImports.push(...path.get("specifiers").map(specifier=>({name:specifier.node.local.name,isAlias:!(specifier.isImportSpecifier()&&t.isIdentifier(specifier.node.imported)&&specifier.node.local.name===specifier.node.imported.name),path:specifier}))),path.node.source.value.startsWith("@storybook")&&path.get("specifiers").forEach(specifier=>{if(specifier.isImportNamespaceSpecifier()&&importedNamespaces.add(specifier.node.local.name),!specifier.isImportSpecifier())return;let imported=specifier.get("imported");if(imported.isIdentifier()&&deprecatedTypes.includes(imported.node.name)){imported.node.name===specifier.node.local.name&&typeReferencesToUpdate.add(specifier.node.local.name);let newType=migrateType(imported.node.name);if(!existingImports.some(it=>it.name===newType))imported.replaceWith(t.identifier(newType)),existingImports.push({name:newType,isAlias:!1,path:specifier});else{let existingImport=existingImports.find(it=>it.name===newType&&it.isAlias);if(existingImport)throw existingImport.path.buildCodeFrameError(`This codemod does not support local imports that are called the same as a storybook import.
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 upgrade_deprecated_types_exports={};__export(upgrade_deprecated_types_exports,{default:()=>transform,parser:()=>parser,upgradeDeprecatedTypes:()=>upgradeDeprecatedTypes});module.exports=__toCommonJS(upgrade_deprecated_types_exports);var import_prettier=__toESM(require("prettier")),babel=__toESM(require("@babel/core")),import_csf_tools=require("@storybook/csf-tools"),t=__toESM(require("@babel/types")),logger=console,deprecatedTypes=["ComponentStory","ComponentStoryFn","ComponentStoryObj","ComponentMeta","Story"];function migrateType(oldType){return oldType==="Story"||oldType==="ComponentStory"?"StoryFn":oldType.replace("Component","")}function transform(info,api,options){let csf=(0,import_csf_tools.loadCsf)(info.source,{makeTitle:title=>title}),fileNode=csf._ast,file=new babel.File({filename:info.path},{code:info.source,ast:fileNode});upgradeDeprecatedTypes(file);let output=(0,import_csf_tools.printCsf)(csf).code;try{let prettierConfig=import_prettier.default.resolveConfig.sync(".",{editorconfig:!0})||{printWidth:100,tabWidth:2,bracketSpacing:!0,trailingComma:"es5",singleQuote:!0};output=import_prettier.default.format(output,{...prettierConfig,filepath:info.path})}catch{logger.log(`Failed applying prettier to ${info.path}.`)}return output}var parser="tsx";function upgradeDeprecatedTypes(file){let importedNamespaces=new Set,typeReferencesToUpdate=new Set,existingImports=[];file.path.traverse({ImportDeclaration:path=>{existingImports.push(...path.get("specifiers").map(specifier=>({name:specifier.node.local.name,isAlias:!(specifier.isImportSpecifier()&&t.isIdentifier(specifier.node.imported)&&specifier.node.local.name===specifier.node.imported.name),path:specifier}))),path.node.source.value.startsWith("@storybook")&&path.get("specifiers").forEach(specifier=>{if(specifier.isImportNamespaceSpecifier()&&importedNamespaces.add(specifier.node.local.name),!specifier.isImportSpecifier())return;let imported=specifier.get("imported");if(imported.isIdentifier()&&deprecatedTypes.includes(imported.node.name)){imported.node.name===specifier.node.local.name&&typeReferencesToUpdate.add(specifier.node.local.name);let newType=migrateType(imported.node.name);if(!existingImports.some(it=>it.name===newType))imported.replaceWith(t.identifier(newType)),existingImports.push({name:newType,isAlias:!1,path:specifier});else{let existingImport=existingImports.find(it=>it.name===newType&&it.isAlias);if(existingImport)throw existingImport.path.buildCodeFrameError(`This codemod does not support local imports that are called the same as a storybook import.
2
2
  Rename this local import and try again.`);specifier.remove()}}})}}),file.path.traverse({TSTypeReference:path=>{let typeName=path.get("typeName");if(typeName.isIdentifier())typeReferencesToUpdate.has(typeName.node.name)&&typeName.replaceWith(t.identifier(migrateType(typeName.node.name)));else if(typeName.isTSQualifiedName()){let namespace=typeName.get("left");if(namespace.isIdentifier()&&importedNamespaces.has(namespace.node.name)){let right=typeName.get("right");deprecatedTypes.includes(right.node.name)&&right.replaceWith(t.identifier(migrateType(right.node.name)))}}}})}0&&(module.exports={parser,upgradeDeprecatedTypes});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/codemod",
3
- "version": "0.0.0-pr-23479-sha-bcda497a",
3
+ "version": "0.0.0-pr-23882-sha-6c4dd3dd",
4
4
  "description": "A collection of codemod scripts written with JSCodeshift",
5
5
  "keywords": [
6
6
  "storybook"
@@ -44,14 +44,21 @@
44
44
  "check": "../../../scripts/prepare/check.ts",
45
45
  "prep": "../../../scripts/prepare/bundle.ts"
46
46
  },
47
+ "files": [
48
+ "dist/**/*",
49
+ "README.md",
50
+ "*.js",
51
+ "*.d.ts",
52
+ "!src/**/*"
53
+ ],
47
54
  "dependencies": {
48
- "@babel/core": "^7.22.0",
49
- "@babel/preset-env": "^7.22.0",
50
- "@babel/types": "^7.22.0",
55
+ "@babel/core": "^7.22.9",
56
+ "@babel/preset-env": "^7.22.9",
57
+ "@babel/types": "^7.22.5",
51
58
  "@storybook/csf": "^0.1.0",
52
- "@storybook/csf-tools": "0.0.0-pr-23479-sha-bcda497a",
53
- "@storybook/node-logger": "0.0.0-pr-23479-sha-bcda497a",
54
- "@storybook/types": "0.0.0-pr-23479-sha-bcda497a",
59
+ "@storybook/csf-tools": "0.0.0-pr-23882-sha-6c4dd3dd",
60
+ "@storybook/node-logger": "0.0.0-pr-23882-sha-6c4dd3dd",
61
+ "@storybook/types": "0.0.0-pr-23882-sha-6c4dd3dd",
55
62
  "@types/cross-spawn": "^6.0.2",
56
63
  "cross-spawn": "^7.0.3",
57
64
  "globby": "^11.0.2",
package/project.json DELETED
@@ -1,6 +0,0 @@
1
- {
2
- "name": "@storybook/codemod",
3
- "$schema": "../../node_modules/nx/schemas/project-schema.json",
4
- "implicitDependencies": [],
5
- "type": "library"
6
- }
package/src/index.ts DELETED
@@ -1,103 +0,0 @@
1
- /* eslint-disable no-param-reassign */
2
- /* eslint import/prefer-default-export: "off" */
3
- import fs from 'fs';
4
- import path from 'path';
5
- import { promisify } from 'util';
6
- import globby from 'globby';
7
- import { sync as spawnSync } from 'cross-spawn';
8
- import { jscodeshiftToPrettierParser } from './lib/utils';
9
-
10
- export {
11
- default as updateOrganisationName,
12
- packageNames,
13
- } from './transforms/update-organisation-name';
14
-
15
- export { default as updateAddonInfo } from './transforms/update-addon-info';
16
-
17
- const TRANSFORM_DIR = `${__dirname}/transforms`;
18
-
19
- export function listCodemods() {
20
- return fs
21
- .readdirSync(TRANSFORM_DIR)
22
- .filter((fname) => fname.endsWith('.js'))
23
- .map((fname) => fname.slice(0, -3));
24
- }
25
-
26
- const renameAsync = promisify(fs.rename);
27
-
28
- async function renameFile(file: any, from: any, to: any, { logger }: any) {
29
- const newFile = file.replace(from, to);
30
- logger.log(`Rename: ${file} ${newFile}`);
31
- return renameAsync(file, newFile);
32
- }
33
-
34
- export async function runCodemod(codemod: any, { glob, logger, dryRun, rename, parser }: any) {
35
- const codemods = listCodemods();
36
- if (!codemods.includes(codemod)) {
37
- throw new Error(`Unknown codemod ${codemod}. Run --list for options.`);
38
- }
39
-
40
- let renameParts = null;
41
- if (rename) {
42
- renameParts = rename.split(':');
43
- if (renameParts.length !== 2) {
44
- throw new Error(`Codemod rename: expected format "from:to", got "${rename}"`);
45
- }
46
- }
47
-
48
- // jscodeshift/prettier know how to handle .ts/.tsx extensions,
49
- // so if the user uses one of those globs, we can auto-infer
50
- let inferredParser = parser;
51
- if (!parser) {
52
- const extension = path.extname(glob).slice(1);
53
- const knownParser = jscodeshiftToPrettierParser(extension);
54
- if (knownParser !== 'babel') inferredParser = extension;
55
- }
56
-
57
- const files = await globby([glob, '!**/node_modules', '!**/dist']);
58
- logger.log(`=> Applying ${codemod}: ${files.length} files`);
59
- if (files.length === 0) {
60
- logger.log(`=> No matching files for glob: ${glob}`);
61
- return;
62
- }
63
-
64
- if (!dryRun && files.length > 0) {
65
- const parserArgs = inferredParser ? ['--parser', inferredParser] : [];
66
- const result = spawnSync(
67
- 'node',
68
- [
69
- require.resolve('jscodeshift/bin/jscodeshift'),
70
- // this makes sure codeshift doesn't transform our own source code with babel
71
- // which is faster, and also makes sure the user won't see babel messages such as:
72
- // [BABEL] Note: The code generator has deoptimised the styling of repo/node_modules/prettier/index.js as it exceeds the max of 500KB.
73
- '--no-babel',
74
- '--fail-on-error',
75
- '-t',
76
- `${TRANSFORM_DIR}/${codemod}.js`,
77
- ...parserArgs,
78
- ...files,
79
- ],
80
- {
81
- stdio: 'inherit',
82
- shell: true,
83
- }
84
- );
85
- if (result.status === 1) {
86
- logger.log('Skipped renaming because of errors.');
87
- return;
88
- }
89
- }
90
-
91
- if (!renameParts && codemod === 'mdx-to-csf') {
92
- renameParts = ['.stories.mdx', '.mdx'];
93
- rename = '.stories.mdx:.mdx;';
94
- }
95
-
96
- if (renameParts) {
97
- const [from, to] = renameParts;
98
- logger.log(`=> Renaming ${rename}: ${files.length} files`);
99
- await Promise.all(
100
- files.map((file) => renameFile(file, new RegExp(`${from}$`), to, { logger }))
101
- );
102
- }
103
- }
@@ -1,9 +0,0 @@
1
- import { sanitizeName } from './utils';
2
-
3
- it('should sanitize names', () => {
4
- expect(sanitizeName('basic')).toMatchInlineSnapshot(`"Basic"`);
5
- expect(sanitizeName('with space')).toMatchInlineSnapshot(`"WithSpace"`);
6
- expect(sanitizeName('default')).toMatchInlineSnapshot(`"Default"`);
7
- expect(sanitizeName('w/punctuation')).toMatchInlineSnapshot(`"WPunctuation"`);
8
- expect(sanitizeName('5')).toMatchInlineSnapshot(`"_5"`);
9
- });
package/src/lib/utils.ts DELETED
@@ -1,29 +0,0 @@
1
- import camelCase from 'lodash/camelCase.js';
2
- import upperFirst from 'lodash/upperFirst.js';
3
-
4
- export const sanitizeName = (name: string) => {
5
- let key = upperFirst(camelCase(name));
6
- // prepend _ if name starts with a digit
7
- if (/^\d/.test(key)) {
8
- key = `_${key}`;
9
- }
10
- // prepend _ if name starts with a digit
11
- if (/^\d/.test(key)) {
12
- key = `_${key}`;
13
- }
14
- return key;
15
- };
16
-
17
- export function jscodeshiftToPrettierParser(parser?: string) {
18
- const parserMap: Record<string, string> = {
19
- babylon: 'babel',
20
- flow: 'flow',
21
- ts: 'typescript',
22
- tsx: 'typescript',
23
- };
24
-
25
- if (!parser) {
26
- return 'babel';
27
- }
28
- return parserMap[parser] || 'babel';
29
- }
@@ -1,44 +0,0 @@
1
- /* eslint-disable */
2
- import React from 'react';
3
- import Button from './Button';
4
-
5
- import { storiesOf, configure } from '@storybook/react';
6
- import { action } from '@storybook/addon-actions';
7
-
8
- storiesOf('Button', module).add('basic', () => <Button label="The Button" />);
9
-
10
- storiesOf('Button').add('no module', () => <Button label="The Button" />);
11
-
12
- storiesOf('Button', module).add('with story parameters', () => <Button label="The Button" />, {
13
- header: false,
14
- inline: true,
15
- });
16
-
17
- storiesOf('Button', module)
18
- .addParameters({ foo: 1 })
19
- .add('with kind parameters', () => <Button label="The Button" />);
20
-
21
- storiesOf('Button', module)
22
- .addParameters({ component: Button })
23
- .add('with existing component parameters', () => <Button label="The Button" />);
24
-
25
- storiesOf('Button', module).add('complex story', () => (
26
- <div>
27
- <Button label="The Button" onClick={action('onClick')} />
28
- <br />
29
- </div>
30
- ));
31
-
32
- storiesOf('Root|Some/Button', module).add('with path', () => <Button label="The Button" />);
33
-
34
- storiesOf('Some.Button', module).add('with dot-path', () => <Button label="The Button" />);
35
-
36
- storiesOf('Some.Button', module)
37
- .addDecorator(withKnobs)
38
- .add('with decorator', () => <Button label="The Button" />);
39
-
40
- // This isn't a valid story, but it tests the `import { comp } from ...` case
41
- storiesOf('action', module).add('non-default component export', () => <action />);
42
-
43
- // This shouldn't get modified since the story name doesn't match
44
- storiesOf('something', module).add('non-matching story', () => <Button label="The Button" />);
@@ -1,68 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`add-component-parameters transforms correctly using "add-component-parameters.input.js" data 1`] = `
4
- "/* eslint-disable */
5
- import React from 'react';
6
- import Button from './Button';
7
-
8
- import { storiesOf, configure } from '@storybook/react';
9
- import { action } from '@storybook/addon-actions';
10
-
11
- storiesOf('Button', module).addParameters({
12
- component: Button
13
- }).add('basic', () => <Button label=\\"The Button\\" />);
14
-
15
- storiesOf('Button').addParameters({
16
- component: Button
17
- }).add('no module', () => <Button label=\\"The Button\\" />);
18
-
19
- storiesOf('Button', module).addParameters({
20
- component: Button
21
- }).add('with story parameters', () => <Button label=\\"The Button\\" />, {
22
- header: false,
23
- inline: true,
24
- });
25
-
26
- storiesOf('Button', module).addParameters({
27
- component: Button
28
- })
29
- .addParameters({ foo: 1 })
30
- .add('with kind parameters', () => <Button label=\\"The Button\\" />);
31
-
32
- storiesOf('Button', module).addParameters({
33
- component: Button
34
- })
35
- .addParameters({ component: Button })
36
- .add('with existing component parameters', () => <Button label=\\"The Button\\" />);
37
-
38
- storiesOf('Button', module).addParameters({
39
- component: Button
40
- }).add('complex story', () => (
41
- <div>
42
- <Button label=\\"The Button\\" onClick={action('onClick')} />
43
- <br />
44
- </div>
45
- ));
46
-
47
- storiesOf('Root|Some/Button', module).addParameters({
48
- component: Button
49
- }).add('with path', () => <Button label=\\"The Button\\" />);
50
-
51
- storiesOf('Some.Button', module).addParameters({
52
- component: Button
53
- }).add('with dot-path', () => <Button label=\\"The Button\\" />);
54
-
55
- storiesOf('Some.Button', module).addParameters({
56
- component: Button
57
- })
58
- .addDecorator(withKnobs)
59
- .add('with decorator', () => <Button label=\\"The Button\\" />);
60
-
61
- // This isn't a valid story, but it tests the \`import { comp } from ...\` case
62
- storiesOf('action', module).addParameters({
63
- component: action
64
- }).add('non-default component export', () => <action />);
65
-
66
- // This shouldn't get modified since the story name doesn't match
67
- storiesOf('something', module).add('non-matching story', () => <Button label=\\"The Button\\" />);"
68
- `;
@@ -1,25 +0,0 @@
1
- import React from 'react';
2
- import Button from './Button';
3
- import { action } from '@storybook/addon-actions';
4
-
5
- export default {
6
- title: 'Button',
7
- };
8
-
9
- export const story1 = () => <Button label="Story 1" />;
10
-
11
- export const story2 = () => <Button label="Story 2" onClick={action('click')} />;
12
- story2.story = { name: 'second story' };
13
-
14
- export const story3 = () => (
15
- <div>
16
- <Button label="The Button" onClick={action('onClick')} />
17
- <br />
18
- </div>
19
- );
20
- const baz = 17;
21
- story3.story = {
22
- name: 'complex story',
23
- parameters: { foo: { bar: baz } },
24
- decorators: [(storyFn) => <bar>{storyFn}</bar>],
25
- };
@@ -1,27 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`csf-hoist-story-annotations transforms correctly using "basic.input.js" data 1`] = `
4
- "import React from 'react';
5
- import Button from './Button';
6
- import { action } from '@storybook/addon-actions';
7
-
8
- export default {
9
- title: 'Button',
10
- };
11
-
12
- export const story1 = () => <Button label=\\"Story 1\\" />;
13
-
14
- export const story2 = () => <Button label=\\"Story 2\\" onClick={action('click')} />;
15
- story2.storyName = 'second story';
16
-
17
- export const story3 = () => (
18
- <div>
19
- <Button label=\\"The Button\\" onClick={action('onClick')} />
20
- <br />
21
- </div>
22
- );
23
- const baz = 17;
24
- story3.storyName = 'complex story';
25
- story3.parameters = { foo: { bar: baz } };
26
- story3.decorators = [(storyFn) => <bar>{storyFn}</bar>];"
27
- `;
@@ -1,25 +0,0 @@
1
- import React from 'react';
2
- import Button from './Button';
3
- import { action } from '@storybook/addon-actions';
4
-
5
- export default {
6
- title: 'Button',
7
- };
8
-
9
- export const story1 = () => <Button label="Story 1" />;
10
-
11
- export const story2 = () => <Button label="Story 2" onClick={action('click')} />;
12
- story2.story = { name: 'second story' };
13
- story2.story.parameters = { foo: 'bar' };
14
-
15
- export const story3 = () => (
16
- <div>
17
- <Button label="The Button" onClick={action('onClick')} />
18
- <br />
19
- </div>
20
- );
21
- const baz = 17;
22
- story3.story = {};
23
- story3.story.name = 'complex story';
24
- story3.story.parameters = { foo: { bar: baz } };
25
- story3.story.decorators = [(storyFn) => <bar>{storyFn}</bar>];
@@ -1,28 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`csf-hoist-story-annotations transforms correctly using "overrides.input.js" data 1`] = `
4
- "import React from 'react';
5
- import Button from './Button';
6
- import { action } from '@storybook/addon-actions';
7
-
8
- export default {
9
- title: 'Button',
10
- };
11
-
12
- export const story1 = () => <Button label=\\"Story 1\\" />;
13
-
14
- export const story2 = () => <Button label=\\"Story 2\\" onClick={action('click')} />;
15
- story2.storyName = 'second story';
16
- story2.parameters = { foo: 'bar' };
17
-
18
- export const story3 = () => (
19
- <div>
20
- <Button label=\\"The Button\\" onClick={action('onClick')} />
21
- <br />
22
- </div>
23
- );
24
- const baz = 17;
25
- story3.storyName = 'complex story';
26
- story3.parameters = { foo: { bar: baz } };
27
- story3.decorators = [(storyFn) => <bar>{storyFn}</bar>];"
28
- `;
@@ -1,13 +0,0 @@
1
- import React from 'react';
2
- import Button from './Button';
3
-
4
- const foo = {
5
- title: 'Button',
6
- };
7
-
8
- export default foo;
9
-
10
- const bar = () => <Button label="Story 1" />;
11
- bar.story = { name: 'bar bar' };
12
-
13
- export const story1 = bar;
@@ -1,17 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`csf-hoist-story-annotations transforms correctly using "variable.input.js" data 1`] = `
4
- "import React from 'react';
5
- import Button from './Button';
6
-
7
- const foo = {
8
- title: 'Button',
9
- };
10
-
11
- export default foo;
12
-
13
- const bar = () => <Button label=\\"Story 1\\" />;
14
- bar.story = { name: 'bar bar' };
15
-
16
- export const story1 = bar;"
17
- `;
@@ -1,18 +0,0 @@
1
- import Button from './Button';
2
- import { action } from '@storybook/addon-actions';
3
- import { Meta, Story } from '@storybook/addon-docs';
4
-
5
- <Meta title='Button' />
6
-
7
- <Story name='story1'><Button label='Story 1' /></Story>
8
-
9
- <Story name='second story'><Button label='Story 2' onClick={action('click')} /></Story>
10
-
11
- <Story name='complex story'><div>
12
- <Button label='The Button' onClick={action('onClick')} />
13
- <br />
14
- </div></Story>
15
-
16
- <Story name='w/punctuation'>
17
- <Button label='w/punctuation'/>
18
- </Story>
@@ -1,40 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`mdx-to-csf transforms correctly using "basic.input.js" data 1`] = `
4
- "import React from 'react';
5
- import Button from './Button';
6
- import { action } from '@storybook/addon-actions';
7
-
8
- export default {
9
- title: 'Button',
10
- };
11
-
12
- export const Story1 = () => <Button label=\\"Story 1\\" />;
13
-
14
- Story1.story = {
15
- name: 'story1',
16
- };
17
-
18
- export const SecondStory = () => <Button label=\\"Story 2\\" onClick={action('click')} />;
19
-
20
- SecondStory.story = {
21
- name: 'second story',
22
- };
23
-
24
- export const ComplexStory = () => (
25
- <div>
26
- <Button label=\\"The Button\\" onClick={action('onClick')} />
27
- <br />
28
- </div>
29
- );
30
-
31
- ComplexStory.story = {
32
- name: 'complex story',
33
- };
34
-
35
- export const WPunctuation = () => <Button label=\\"w/punctuation\\" />;
36
-
37
- WPunctuation.story = {
38
- name: 'w/punctuation',
39
- };"
40
- `;
@@ -1,6 +0,0 @@
1
- import Button from './Button';
2
- import { Meta, Story } from '@storybook/addon-docs';
3
-
4
- <Meta title='Button' id="button-id" />
5
-
6
- <Story name='story1'><Button label='Story 1' /></Story>
@@ -1,17 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`mdx-to-csf transforms correctly using "component-id.input.js" data 1`] = `
4
- "import React from 'react';
5
- import Button from './Button';
6
-
7
- export default {
8
- title: 'Button',
9
- id: 'button-id',
10
- };
11
-
12
- export const Story1 = () => <Button label=\\"Story 1\\" />;
13
-
14
- Story1.story = {
15
- name: 'story1',
16
- };"
17
- `;
@@ -1,8 +0,0 @@
1
- import Button from './Button';
2
- import { Meta, Story } from '@storybook/addon-docs';
3
-
4
- <Meta
5
- title='Some.Button'
6
- decorators={[withKnobs, storyFn => <div className='foo'>{storyFn}</div>]} />
7
-
8
- <Story name='with decorator' decorators={[withKnobs]}><Button label='The Button' /></Story>
@@ -1,18 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`mdx-to-csf transforms correctly using "decorators.input.js" data 1`] = `
4
- "import React from 'react';
5
- import Button from './Button';
6
-
7
- export default {
8
- title: 'Some.Button',
9
- decorators: [withKnobs, (storyFn) => <div className=\\"foo\\">{storyFn}</div>],
10
- };
11
-
12
- export const WithDecorator = () => <Button label=\\"The Button\\" />;
13
-
14
- WithDecorator.story = {
15
- name: 'with decorator',
16
- decorators: [withKnobs],
17
- };"
18
- `;
@@ -1,19 +0,0 @@
1
- import Button from './Button';
2
- import { action } from '@storybook/addon-actions';
3
- import { Meta, Story } from '@storybook/addon-docs';
4
-
5
- <Meta title='Button' />
6
-
7
- export const rowData = {
8
- col1: 'a',
9
- col2: 2,
10
- };
11
-
12
- <Story name='story1'><Button label='Story 1' /></Story>
13
-
14
- <Story name='second story'><Button label='Story 2' onClick={action('click')} /></Story>
15
-
16
- <Story name='complex story'><div>
17
- <Button label='The Button' onClick={action('onClick')} />
18
- <br />
19
- </div></Story>