@storybook/codemod 7.0.0-alpha.43 → 7.0.0-alpha.44
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +5 -4
- package/src/transforms/__testfixtures__/update-organisation-name/update-organisation-name.output.snapshot +1 -1
- package/src/transforms/__tests__/transforms.tests.js +4 -5
- package/src/transforms/csf-2-to-3.ts +2 -2
- package/src/transforms/update-organisation-name.js +1 -1
package/dist/index.d.ts
CHANGED
@@ -20,7 +20,7 @@ const packageNames = {
|
|
20
20
|
'@kadira/storybook-channels': '@storybook/channels',
|
21
21
|
'@kadira/storybook-channel-postmsg': '@storybook/channel-postmessage',
|
22
22
|
'@kadira/storybook-channel-websocket': '@storybook/channel-websocket',
|
23
|
-
'@kadira/storybook-ui': '@storybook/
|
23
|
+
'@kadira/storybook-ui': '@storybook/manager',
|
24
24
|
'@kadira/react-native-storybook': '@storybook/react-native',
|
25
25
|
'@kadira/react-storybook': '@storybook/react',
|
26
26
|
'@kadira/getstorybook': '@storybook/cli',
|
package/dist/index.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
var R=Object.create;var l=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,S=Object.prototype.hasOwnProperty;var W=(o,r)=>{for(var t in r)l(o,t,{get:r[t],enumerable:!0})},h=(o,r,t,a)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of A(r))!S.call(o,n)&&n!==t&&l(o,n,{get:()=>r[n],enumerable:!(a=N(r,n))||a.enumerable});return o};var f=(o,r,t)=>(t=o!=null?R(C(o)):{},h(r||!o||!o.__esModule?l(t,"default",{value:o,enumerable:!0}):t,o)),_=o=>h(l({},"__esModule",{value:!0}),o);var z={};W(z,{listCodemods:()=>E,packageNames:()=>m,runCodemod:()=>q,updateAddonInfo:()=>b,updateOrganisationName:()=>y});module.exports=_(z);var u=f(require("fs")),x=f(require("path")),w=require("util"),$=f(require("globby")),I=require("cross-spawn");var v=f(require("lodash/camelCase")),D=f(require("lodash/upperFirst"));function g(o){let r={babylon:"babel",flow:"flow",ts:"typescript",tsx:"typescript"};return o&&r[o]||"babel"}var m={"@kadira/react-storybook-decorator-centered":"@storybook/addon-centered","@kadira/storybook-addons":"@storybook/addons","@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/channels","@kadira/storybook-channel-postmsg":"@storybook/channel-postmessage","@kadira/storybook-channel-websocket":"@storybook/channel-websocket","@kadira/storybook-ui":"@storybook/
|
1
|
+
var R=Object.create;var l=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,S=Object.prototype.hasOwnProperty;var W=(o,r)=>{for(var t in r)l(o,t,{get:r[t],enumerable:!0})},h=(o,r,t,a)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of A(r))!S.call(o,n)&&n!==t&&l(o,n,{get:()=>r[n],enumerable:!(a=N(r,n))||a.enumerable});return o};var f=(o,r,t)=>(t=o!=null?R(C(o)):{},h(r||!o||!o.__esModule?l(t,"default",{value:o,enumerable:!0}):t,o)),_=o=>h(l({},"__esModule",{value:!0}),o);var z={};W(z,{listCodemods:()=>E,packageNames:()=>m,runCodemod:()=>q,updateAddonInfo:()=>b,updateOrganisationName:()=>y});module.exports=_(z);var u=f(require("fs")),x=f(require("path")),w=require("util"),$=f(require("globby")),I=require("cross-spawn");var v=f(require("lodash/camelCase")),D=f(require("lodash/upperFirst"));function g(o){let r={babylon:"babel",flow:"flow",ts:"typescript",tsx:"typescript"};return o&&r[o]||"babel"}var m={"@kadira/react-storybook-decorator-centered":"@storybook/addon-centered","@kadira/storybook-addons":"@storybook/addons","@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/channels","@kadira/storybook-channel-postmsg":"@storybook/channel-postmessage","@kadira/storybook-channel-websocket":"@storybook/channel-websocket","@kadira/storybook-ui":"@storybook/manager","@kadira/react-native-storybook":"@storybook/react-native","@kadira/react-storybook":"@storybook/react","@kadira/getstorybook":"@storybook/cli","@kadira/storybook":"@storybook/react",storyshots:"@storybook/addon-storyshots",getstorybook:"@storybook/cli"};function y(o,r){let t=r.jscodeshift,a=Object.keys(m),n=s=>a.find(e=>s.match(e)),c=s=>{let e=n(s);if(e){let i=m[e];return s.replace(e,i)}return s},p=s=>(s.node.source.value=c(s.node.source.value),s.node);return t(o.source).find(t.ImportDeclaration).replaceWith(p).toSource({quote:"single"})}function b(o,r){let t=r.jscodeshift,a=t(o.source),n=e=>e[3]===void 0?e[2]===void 0?[e[0]]:[e[1]]:[t.objectExpression([t.property("init",t.identifier("text"),e[1]),...e[3].properties])],c=e=>{let{node:i}=e,d=i.arguments,k=d[2]?d[2]:d[1];return i.callee.property.name="add",i.arguments=[d[0],t.callExpression(t.callExpression(t.identifier("withInfo"),n(d)),[k])],i},p=()=>{a.find(t.ImportDeclaration).filter(i=>i.node.source.value==="@storybook/addon-info").size()||a.find(t.ImportDeclaration).at(-1).insertAfter(t.importDeclaration([t.importSpecifier(t.identifier("withInfo"))],t.literal("@storybook/addon-info")))},s=a.find(t.CallExpression,{callee:{property:{name:"addWithInfo"}}});return s.size()&&(p(),s.replaceWith(c)),a.toSource()}var j=`${__dirname}/transforms`;function E(){return u.default.readdirSync(j).filter(o=>o.endsWith(".js")).map(o=>o.slice(0,-3))}var F=(0,w.promisify)(u.default.rename);async function O(o,r,t,{logger:a}){let n=o.replace(r,t);return a.log(`Rename: ${o} ${n}`),F(o,n)}async function q(o,{glob:r,logger:t,dryRun:a,rename:n,parser:c}){if(!E().includes(o))throw new Error(`Unknown codemod ${o}. Run --list for options.`);let s=null;if(n&&(s=n.split(":"),s.length!==2))throw new Error(`Codemod rename: expected format "from:to", got "${n}"`);let e=c;if(!c){let d=x.default.extname(r).slice(1);g(d)!=="babel"&&(e=d)}let i=await(0,$.default)([r,"!**/node_modules","!**/dist"]);if(t.log(`=> Applying ${o}: ${i.length} files`),!a){let d=e?["--parser",e]:[];(0,I.sync)("npx",["jscodeshift","-t",`${j}/${o}.js`,...d,...i],{stdio:"inherit",shell:!0})}if(s){let[d,k]=s;t.log(`=> Renaming ${n}: ${i.length} files`),await Promise.all(i.map(P=>O(P,new RegExp(`${d}$`),k,{logger:t})))}}0&&(module.exports={listCodemods,packageNames,runCodemod,updateAddonInfo,updateOrganisationName});
|
package/dist/index.mjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
import u from"fs";import x from"path";import{promisify as w}from"util";import $ from"globby";import{sync as I}from"cross-spawn";import N from"lodash/camelCase";import C from"lodash/upperFirst";function m(t){let i={babylon:"babel",flow:"flow",ts:"typescript",tsx:"typescript"};return t&&i[t]||"babel"}var l={"@kadira/react-storybook-decorator-centered":"@storybook/addon-centered","@kadira/storybook-addons":"@storybook/addons","@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/channels","@kadira/storybook-channel-postmsg":"@storybook/channel-postmessage","@kadira/storybook-channel-websocket":"@storybook/channel-websocket","@kadira/storybook-ui":"@storybook/
|
1
|
+
import u from"fs";import x from"path";import{promisify as w}from"util";import $ from"globby";import{sync as I}from"cross-spawn";import N from"lodash/camelCase";import C from"lodash/upperFirst";function m(t){let i={babylon:"babel",flow:"flow",ts:"typescript",tsx:"typescript"};return t&&i[t]||"babel"}var l={"@kadira/react-storybook-decorator-centered":"@storybook/addon-centered","@kadira/storybook-addons":"@storybook/addons","@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/channels","@kadira/storybook-channel-postmsg":"@storybook/channel-postmessage","@kadira/storybook-channel-websocket":"@storybook/channel-websocket","@kadira/storybook-ui":"@storybook/manager","@kadira/react-native-storybook":"@storybook/react-native","@kadira/react-storybook":"@storybook/react","@kadira/getstorybook":"@storybook/cli","@kadira/storybook":"@storybook/react",storyshots:"@storybook/addon-storyshots",getstorybook:"@storybook/cli"};function y(t,i){let o=i.jscodeshift,d=Object.keys(l),a=e=>d.find(r=>e.match(r)),c=e=>{let r=a(e);if(r){let n=l[r];return e.replace(r,n)}return e},f=e=>(e.node.source.value=c(e.node.source.value),e.node);return o(t.source).find(o.ImportDeclaration).replaceWith(f).toSource({quote:"single"})}function b(t,i){let o=i.jscodeshift,d=o(t.source),a=r=>r[3]===void 0?r[2]===void 0?[r[0]]:[r[1]]:[o.objectExpression([o.property("init",o.identifier("text"),r[1]),...r[3].properties])],c=r=>{let{node:n}=r,s=n.arguments,p=s[2]?s[2]:s[1];return n.callee.property.name="add",n.arguments=[s[0],o.callExpression(o.callExpression(o.identifier("withInfo"),a(s)),[p])],n},f=()=>{d.find(o.ImportDeclaration).filter(n=>n.node.source.value==="@storybook/addon-info").size()||d.find(o.ImportDeclaration).at(-1).insertAfter(o.importDeclaration([o.importSpecifier(o.identifier("withInfo"))],o.literal("@storybook/addon-info")))},e=d.find(o.CallExpression,{callee:{property:{name:"addWithInfo"}}});return e.size()&&(f(),e.replaceWith(c)),d.toSource()}var h=`${__dirname}/transforms`;function j(){return u.readdirSync(h).filter(t=>t.endsWith(".js")).map(t=>t.slice(0,-3))}var E=w(u.rename);async function P(t,i,o,{logger:d}){let a=t.replace(i,o);return d.log(`Rename: ${t} ${a}`),E(t,a)}async function M(t,{glob:i,logger:o,dryRun:d,rename:a,parser:c}){if(!j().includes(t))throw new Error(`Unknown codemod ${t}. Run --list for options.`);let e=null;if(a&&(e=a.split(":"),e.length!==2))throw new Error(`Codemod rename: expected format "from:to", got "${a}"`);let r=c;if(!c){let s=x.extname(i).slice(1);m(s)!=="babel"&&(r=s)}let n=await $([i,"!**/node_modules","!**/dist"]);if(o.log(`=> Applying ${t}: ${n.length} files`),!d){let s=r?["--parser",r]:[];I("npx",["jscodeshift","-t",`${h}/${t}.js`,...s,...n],{stdio:"inherit",shell:!0})}if(e){let[s,p]=e;o.log(`=> Renaming ${a}: ${n.length} files`),await Promise.all(n.map(g=>P(g,new RegExp(`${s}$`),p,{logger:o})))}}export{j as listCodemods,l as packageNames,M as runCodemod,b as updateAddonInfo,y as updateOrganisationName};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@storybook/codemod",
|
3
|
-
"version": "7.0.0-alpha.
|
3
|
+
"version": "7.0.0-alpha.44",
|
4
4
|
"description": "A collection of codemod scripts written with JSCodeshift",
|
5
5
|
"keywords": [
|
6
6
|
"storybook"
|
@@ -39,8 +39,9 @@
|
|
39
39
|
"dependencies": {
|
40
40
|
"@babel/types": "^7.12.11",
|
41
41
|
"@storybook/csf": "next",
|
42
|
-
"@storybook/csf-tools": "7.0.0-alpha.
|
43
|
-
"@storybook/node-logger": "7.0.0-alpha.
|
42
|
+
"@storybook/csf-tools": "7.0.0-alpha.44",
|
43
|
+
"@storybook/node-logger": "7.0.0-alpha.44",
|
44
|
+
"@storybook/types": "7.0.0-alpha.44",
|
44
45
|
"cross-spawn": "^7.0.3",
|
45
46
|
"globby": "^11.0.2",
|
46
47
|
"jscodeshift": "^0.13.1",
|
@@ -63,5 +64,5 @@
|
|
63
64
|
"./src/index.js"
|
64
65
|
]
|
65
66
|
},
|
66
|
-
"gitHead": "
|
67
|
+
"gitHead": "d4965bd328d8f83c279560c7bc8428e490b275f3"
|
67
68
|
}
|
@@ -13,9 +13,8 @@ fs.readdirSync(fixturesDir).forEach((transformName) => {
|
|
13
13
|
if (transformName === 'mdx-to-csf') return;
|
14
14
|
|
15
15
|
const transformFixturesDir = path.join(fixturesDir, transformName);
|
16
|
-
describe(transformName
|
17
|
-
fs
|
18
|
-
.readdirSync(transformFixturesDir)
|
16
|
+
describe(`${transformName}`, () => {
|
17
|
+
fs.readdirSync(transformFixturesDir)
|
19
18
|
.filter((fileName) => inputRegExp.test(fileName))
|
20
19
|
.forEach((fileName) => {
|
21
20
|
const inputPath = path.join(transformFixturesDir, fileName);
|
@@ -28,6 +27,6 @@ fs.readdirSync(fixturesDir).forEach((transformName) => {
|
|
28
27
|
{ path: inputPath, source: fs.readFileSync(inputPath, 'utf8') }
|
29
28
|
)
|
30
29
|
).toMatchSpecificSnapshot(inputPath.replace(inputRegExp, '.output.snapshot')));
|
31
|
-
})
|
32
|
-
);
|
30
|
+
});
|
31
|
+
});
|
33
32
|
});
|
@@ -6,7 +6,7 @@ import { jscodeshiftToPrettierParser } from '../lib/utils';
|
|
6
6
|
|
7
7
|
const logger = console;
|
8
8
|
|
9
|
-
const
|
9
|
+
const renameAnnotation = (annotation: string) => {
|
10
10
|
return annotation === 'storyName' ? 'name' : annotation;
|
11
11
|
};
|
12
12
|
|
@@ -104,7 +104,7 @@ function transform({ source }: { source: string }, api: any, options: { parser?:
|
|
104
104
|
const objectExports: Record<string, t.Statement> = {};
|
105
105
|
Object.entries(csf._storyExports).forEach(([key, decl]) => {
|
106
106
|
const annotations = Object.entries(csf._storyAnnotations[key]).map(([annotation, val]) => {
|
107
|
-
return t.objectProperty(t.identifier(
|
107
|
+
return t.objectProperty(t.identifier(renameAnnotation(annotation)), val as t.Expression);
|
108
108
|
});
|
109
109
|
|
110
110
|
if (t.isVariableDeclarator(decl)) {
|
@@ -12,7 +12,7 @@ export const packageNames = {
|
|
12
12
|
'@kadira/storybook-channels': '@storybook/channels',
|
13
13
|
'@kadira/storybook-channel-postmsg': '@storybook/channel-postmessage',
|
14
14
|
'@kadira/storybook-channel-websocket': '@storybook/channel-websocket',
|
15
|
-
'@kadira/storybook-ui': '@storybook/
|
15
|
+
'@kadira/storybook-ui': '@storybook/manager',
|
16
16
|
'@kadira/react-native-storybook': '@storybook/react-native',
|
17
17
|
'@kadira/react-storybook': '@storybook/react',
|
18
18
|
'@kadira/getstorybook': '@storybook/cli',
|