@storybook/codemod 0.0.0-pr-30162-sha-fc2610f4 → 0.0.0-pr-30197-sha-861625a8
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.
@@ -0,0 +1 @@
|
|
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_3_to_4_exports={};__export(csf_3_to_4_exports,{default:()=>transform});module.exports=__toCommonJS(csf_3_to_4_exports);var import_csf_tools=require("@storybook/core/csf-tools"),babel=__toESM(require("@babel/core")),import_types=require("@babel/types");async function transform(info){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}),metaVariableName="meta",programNode=fileNode.program,foundConfigImport=!1;programNode.body.forEach(node=>{(0,import_types.isImportDeclaration)(node)&&(0,import_csf_tools.isValidPreviewPath)(node.source.value)&&(node.specifiers.some(specifier=>(0,import_types.isImportSpecifier)(specifier)&&(0,import_types.isIdentifier)(specifier.imported,{name:"config"}))||node.specifiers.push(babel.types.importSpecifier(babel.types.identifier("config"),babel.types.identifier("config"))),foundConfigImport=!0)});let hasMeta=!1;if(file.path.traverse({ExportDefaultDeclaration:path=>{hasMeta=!0;let declaration=path.node.declaration;if((0,import_types.isObjectExpression)(declaration)){let metaVariable=babel.types.variableDeclaration("const",[babel.types.variableDeclarator(babel.types.identifier(metaVariableName),babel.types.callExpression(babel.types.memberExpression(babel.types.identifier("config"),babel.types.identifier("meta")),[declaration]))]);path.replaceWith(metaVariable)}else if((0,import_types.isIdentifier)(declaration)){let binding=path.scope.getBinding(declaration.name);if(binding&&binding.path.isVariableDeclarator()){let originalName=declaration.name;binding.path.node.id=babel.types.identifier(metaVariableName);let init=binding.path.node.init;((0,import_types.isTSSatisfiesExpression)(init)||(0,import_types.isTSAsExpression)(init))&&(init=init.expression),(0,import_types.isObjectExpression)(init)&&(binding.path.node.init=babel.types.callExpression(babel.types.memberExpression(babel.types.identifier("config"),babel.types.identifier("meta")),[init])),path.scope.rename(originalName,metaVariableName)}path.remove()}},ExportNamedDeclaration:path=>{let declaration=path.node.declaration;!declaration||!(0,import_types.isVariableDeclaration)(declaration)||!hasMeta||declaration.declarations.forEach(decl=>{let id=decl.id,init=decl.init;(0,import_types.isIdentifier)(id)&&init&&(((0,import_types.isTSSatisfiesExpression)(init)||(0,import_types.isTSAsExpression)(init))&&(init=init.expression),(0,import_types.isObjectExpression)(init)&&(id.typeAnnotation&&(id.typeAnnotation=null),decl.init=babel.types.callExpression(babel.types.memberExpression(babel.types.identifier(metaVariableName),babel.types.identifier("story")),[init])))})}}),hasMeta&&!foundConfigImport){let configImport=babel.types.importDeclaration([babel.types.importSpecifier(babel.types.identifier("config"),babel.types.identifier("config"))],babel.types.stringLiteral("#.storybook/preview"));programNode.body.unshift(configImport)}let{code}=babel.transformFromAstSync(fileNode,info.source,{parserOpts:{sourceType:"module"}});return code}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@storybook/codemod",
|
3
|
-
"version": "0.0.0-pr-
|
3
|
+
"version": "0.0.0-pr-30197-sha-861625a8",
|
4
4
|
"description": "A collection of codemod scripts written with JSCodeshift",
|
5
5
|
"keywords": [
|
6
6
|
"storybook"
|
@@ -28,6 +28,7 @@
|
|
28
28
|
},
|
29
29
|
"./dist/transforms/add-component-parameters.js": "./dist/transforms/add-component-parameters.js",
|
30
30
|
"./dist/transforms/csf-2-to-3.js": "./dist/transforms/csf-2-to-3.js",
|
31
|
+
"./dist/transforms/csf-3-to-4.js": "./dist/transforms/csf-3-to-4.js",
|
31
32
|
"./dist/transforms/csf-hoist-story-annotations.js": "./dist/transforms/csf-hoist-story-annotations.js",
|
32
33
|
"./dist/transforms/find-implicit-spies.js": "./dist/transforms/find-implicit-spies.js",
|
33
34
|
"./dist/transforms/move-builtin-addons.js": "./dist/transforms/move-builtin-addons.js",
|
@@ -57,7 +58,7 @@
|
|
57
58
|
"@babel/core": "^7.24.4",
|
58
59
|
"@babel/preset-env": "^7.24.4",
|
59
60
|
"@babel/types": "^7.24.0",
|
60
|
-
"@storybook/core": "0.0.0-pr-
|
61
|
+
"@storybook/core": "0.0.0-pr-30197-sha-861625a8",
|
61
62
|
"@storybook/csf": "0.1.12",
|
62
63
|
"@types/cross-spawn": "^6.0.2",
|
63
64
|
"cross-spawn": "^7.0.3",
|
@@ -90,14 +91,15 @@
|
|
90
91
|
"bundler": {
|
91
92
|
"entries": [
|
92
93
|
"./src/index.ts",
|
93
|
-
"./src/transforms/
|
94
|
+
"./src/transforms/storiesof-to-csf.js",
|
95
|
+
"./src/transforms/mdx-to-csf.ts",
|
94
96
|
"./src/transforms/csf-2-to-3.ts",
|
97
|
+
"./src/transforms/csf-3-to-4.ts",
|
95
98
|
"./src/transforms/csf-hoist-story-annotations.js",
|
96
99
|
"./src/transforms/find-implicit-spies.ts",
|
97
|
-
"./src/transforms/
|
100
|
+
"./src/transforms/add-component-parameters.js",
|
98
101
|
"./src/transforms/migrate-to-test-package.ts",
|
99
102
|
"./src/transforms/move-builtin-addons.js",
|
100
|
-
"./src/transforms/storiesof-to-csf.js",
|
101
103
|
"./src/transforms/update-addon-info.js",
|
102
104
|
"./src/transforms/update-organisation-name.js",
|
103
105
|
"./src/transforms/upgrade-deprecated-types.ts",
|