@storybook/bench
Advanced tools
Comparing version 1.0.0-next.2 to 1.0.0-next.3
@@ -230,3 +230,3 @@ 'use strict'; | ||
const installAddonBench = async () => { | ||
let commandArgs = ['add', '@storybook/addon-bench@0.0.3-canary.4.cc1f164.0', '--dev']; | ||
let commandArgs = ['add', '@storybook/addon-bench@next', '--dev']; | ||
@@ -233,0 +233,0 @@ if (isUsingYarn1()) { |
@@ -1,2 +0,2 @@ | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("jsonexport")),r=e(require("commander")),a=e(require("fs")),i=require("exectimer"),o=require("cross-spawn"),s=e(require("du")),n=e(require("fs-extra")),l=e(require("path")),c=e(require("rimraf")),m=require("playwright"),w=e(require("@hapi/hapi")),d=e(require("@hapi/inert")),u=require("@google-cloud/bigquery"),p=e(require("lodash/mapValues"));require("pretty-bytes");const g=["managerRender","previewRender"],b=["--no-sandbox","--disable-setuid-sandbox"],h=()=>(new Date).getTime(),y=e=>{const t=e||{init:h(),time:{}};return t.init=h(),g.forEach(e=>t.time[e]=null),t},v=async(e,t)=>{const r=new w.Server({host:"localhost",port:9898});return g.forEach(a=>{var i;r.route({method:"GET",path:"/"+(i=a),handler:async(r,a)=>(console.log("HANDLER: "+i,e),e.time[i]||(e.time[i]=1e6*(h()-e.init)),"previewRender"===i&&t(),a.response("ok").code(200))})}),await r.start(),r},f=/<script.*?src="(.[^"]*\.js)">/g,k=console,S=e=>Array.from(e.matchAll(f)).map(e=>e[1]),j=async(e,t,r,a)=>{let i=r.find(e=>e.startsWith(t)),o=a.find(e=>e.startsWith(t));if("vendors"===t&&(o=o||a.find(e=>!e.startsWith("main")&&!e.startsWith("runtime")),i=i||r.find(e=>!e.startsWith("main")&&!e.startsWith("runtime"))),i||"main"!==t||(i=r.find(e=>e.startsWith("/assets/iframe"))),await n.pathExists(l.join(e,"sb-manager"))&&(o="sb-manager"),!o)throw new Error(`Missing manager files for '${t}')}`);return{manager:"sb-manager"===o&&"main"!==t?0:await s(l.join(e,o)),preview:i?await s(l.join(e,i)):0}},z=async e=>{try{return await s(e)}catch{return 0}},x=/(addons.*\:.*\[)/g,_=/^.\s+(\d+\.?\d*) (m?s) for manager and (\d+\.?\d*) (m?s) for preview/m,D=/^.\s+(\d+\.?\d*) (m?s) for preview/m,E=console,R=(e,t)=>{if("ms"===t)return 1e6*parseFloat(e);if("s"===t)return 1e9*parseFloat(e);throw new Error("Unexpected unit of time "+t)},q=JSON.parse(process.env.GCP_CREDENTIALS||"{}"),P="true"===process.env.SB_BENCH_UPLOAD,{CIRCLE_BRANCH:C,CIRCLE_SHA1:T}=process.env,W=e=>{const t=o.sync("git",e,{stdio:"pipe"});if(t.error)throw t.error;return t.output.join("\n").trim()},F=(e,t)=>"object"==typeof e?p(e,e=>F(e,t)):t(e),A=e=>Math.round(e/1e6),M=e=>Math.round(e/1024);exports.main=async()=>{r.arguments("[installCommand]"),r.option("-l, --label <label>","Save as <label>.csv/json and upload with <label> if SB_BENCH_UPLOAD is true","bench"),r.option("-e, --extra-flags <flags>",'Run storybook with extra flags (e.g. "--no-dll")',""),r.option("--no-install","Do not measure storybook install time"),r.option("--no-start","Do not measure storybook start time"),r.option("--no-browse","Do not measure storybook browse time"),r.parse(process.argv),r.install&&!r.args.length&&r.help();const{label:e,extraFlags:g,install:h,start:f,browse:N}=r,B=r.args[0],H=g.length>0?g.split(" "):[],L=await(async({installCommand:e,label:r,extraFlags:u,benchmarks:g})=>{await(async()=>{c.sync("storybook-static")})();const h=(f={install:g.install?await(async e=>{if(console.log("measuring install"),!e)return console.warn("No install command provided"),{size:{total:0},time:{total:0}};const t=await s("node_modules");i.Tick.wrap((function(t){const[r,...a]=e.split(" ");o.sync(r,a,{stdio:"inherit"}),t()}));const r=await s("node_modules");return await(async()=>{let e=["add","@storybook/addon-bench@0.0.3-canary.4.cc1f164.0","--dev"];(()=>{const e=o.sync("yarn",["--version"]);if(0!==e.status)throw new Error("๐งถ Yarn must be installed to run '@storybook/bench'");const t=e.output.toString().replace(/,/g,"").replace(/"/g,"");return/^1\.+/.test(t)})()&&e.push("-W"),o.sync("yarn",e,{stdio:"inherit"});const t=["js","cjs","mjs","ts"].map(e=>".storybook/main."+e).find(e=>a.existsSync(e));if(!t)throw new Error("No main.js found!");const r=a.readFileSync(t).toString();if(!r.includes("@storybook/addon-bench")){const e=(e=>e.split("\n").map(e=>e.replace(x,'$1 "@storybook/addon-bench",')).join("\n"))(r);a.writeFileSync(t,e)}})(),{size:{total:r-t},time:{total:i.timers.install.duration()}}})(e):{},start:g.start?await(async e=>{let t;console.log("measuring start-storybook");const r=new Promise(e=>{t=e});let a;const i=new Promise(e=>{a=e}),s=y(),n=o.spawn("yarn",["storybook","-p",9999..toString(),"--ci",...e],{stdio:["inherit","pipe","inherit"]});let l,c=-1,w=-1;n.stdout.on("data",e=>{const r=(e=>{const t=_.exec(e);if(t)return{manager:R(t[1],t[2]),preview:R(t[3],t[4])};const r=D.exec(e);return r?{manager:0,preview:R(r[1],r[2])}:void 0})(e.toString());if(r){const{manager:e,preview:a}=r;w=a,c=e,t()}}),n.on("exit",()=>{E.log("closing start-storybook"),a()});const d=await m.chromium.launch({args:b});l=await v(s,async()=>{E.log("killing start-storybook"),n.kill(),E.log("stopping stats server"),await l.stop(),E.log("closing browser"),await d.close()}),await r;const u=await d.newPage();return await u.goto("http://localhost:9999/"),await i,{time:{managerWebpack:c,previewWebpack:w,...s.time},size:{}}})(u):{},...g.browse?await(async e=>{let t;console.log("measuring build-storybook"),i.Tick.wrap((function(t){o.sync("yarn",["build-storybook",...e],{stdio:"inherit"}),t()}));const r=new Promise((e,r)=>{t=e,setTimeout(r,4e4)}),a=y(),c=await m.chromium.launch({args:b}),u=await(async()=>{const e=new w.Server({host:"localhost",port:9899});return await e.register(d),e.route({method:"GET",path:"/{param*}",handler:async(e,t)=>{const r=l.join(process.cwd(),"storybook-static",e.path);return t.file(r,{confine:!1})}}),await e.start(),console.log("Static server:",e.info.uri),e})();let p;p=await v(a,async()=>{k.log("resolving browse"),t(),k.log("stopping stats server"),await p.stop(),k.log("stopping static server"),await u.stop(),k.log("closing browser"),await c.close()});const g=await c.newPage();await g.goto("http://localhost:9899/index.html"),await r;const h={time:{build:i.timers.build.duration()},size:{}},f=await(async e=>{const t=S((await n.readFile(l.join(e,"iframe.html"))).toString()),r=S((await n.readFile(l.join(e,"index.html"))).toString()),[a,i,o,s,c]=await Promise.all([j(e,"main",t,r),j(e,"runtime",t,r),j(e,"vendors",t,r),z(l.join(e,"sb_dll","storybook_docs_dll.js")),z(l.join(e,"sb_dll","storybook_ui_dll.js"))]);return{manager:{total:a.manager+i.manager+o.manager,main:a.manager,runtime:i.manager,vendors:o.manager,uiDll:c},preview:{total:a.preview+i.preview+o.preview,main:a.preview,runtime:i.preview,vendors:o.preview,docsDll:s}}})("storybook-static");return{build:h,browse:{size:{total:await s("storybook-static"),...f},time:a.time}}})(u):{build:{},browse:{}}},p(f,e=>({time:F(e.time,A),size:F(e.size,M)})));var f;return await(async(e,r)=>{const i=await t(e);a.writeFileSync(r+".csv",i),a.writeFileSync(r+".json",JSON.stringify(e))})(h,r),h})({installCommand:B,label:e,extraFlags:H,benchmarks:{install:h,start:f,browse:N}});P&&await(async({install:e,start:t,build:r,browse:a},i)=>{console.log("uploading to label",i);const o={branch:C||W(["rev-parse","--abbrev-ref","HEAD"]),commit:T||W(["rev-parse","HEAD"]),timestamp:(new Date).toISOString(),label:i,installTime:e.time.total,installSize:e.size.total,startManagerBuild:t.time.managerWebpack,startPreviewBuild:t.time.previewWebpack,startManagerRender:t.time.managerRender,startPreviewRender:t.time.previewRender,buildTime:r.time.build,browseManagerRender:a.time.managerRender,browsePreviewRender:a.time.previewRender,browseSizeTotal:a.size.total,browseSizeManagerTotal:a.size.manager.total,browseSizeManagerVendors:a.size.manager.vendors,browseSizeManagerUiDll:a.size.manager.uiDll,browseSizePreviewTotal:a.size.preview.total,browseSizePreviewVendors:a.size.preview.vendors,browseSizePreviewDocsDll:a.size.preview.docsDll},s=new u.BigQuery({projectId:q.project_id,credentials:q}).dataset("benchmark_results").table("bench");await s.insert([o])})(L,e)}; | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("jsonexport")),r=e(require("commander")),a=e(require("fs")),i=require("exectimer"),o=require("cross-spawn"),s=e(require("du")),n=e(require("fs-extra")),l=e(require("path")),c=e(require("rimraf")),m=require("playwright"),w=e(require("@hapi/hapi")),d=e(require("@hapi/inert")),u=require("@google-cloud/bigquery"),p=e(require("lodash/mapValues"));require("pretty-bytes");const g=["managerRender","previewRender"],b=["--no-sandbox","--disable-setuid-sandbox"],h=()=>(new Date).getTime(),y=e=>{const t=e||{init:h(),time:{}};return t.init=h(),g.forEach(e=>t.time[e]=null),t},v=async(e,t)=>{const r=new w.Server({host:"localhost",port:9898});return g.forEach(a=>{var i;r.route({method:"GET",path:"/"+(i=a),handler:async(r,a)=>(console.log("HANDLER: "+i,e),e.time[i]||(e.time[i]=1e6*(h()-e.init)),"previewRender"===i&&t(),a.response("ok").code(200))})}),await r.start(),r},f=/<script.*?src="(.[^"]*\.js)">/g,k=console,S=e=>Array.from(e.matchAll(f)).map(e=>e[1]),j=async(e,t,r,a)=>{let i=r.find(e=>e.startsWith(t)),o=a.find(e=>e.startsWith(t));if("vendors"===t&&(o=o||a.find(e=>!e.startsWith("main")&&!e.startsWith("runtime")),i=i||r.find(e=>!e.startsWith("main")&&!e.startsWith("runtime"))),i||"main"!==t||(i=r.find(e=>e.startsWith("/assets/iframe"))),await n.pathExists(l.join(e,"sb-manager"))&&(o="sb-manager"),!o)throw new Error(`Missing manager files for '${t}')}`);return{manager:"sb-manager"===o&&"main"!==t?0:await s(l.join(e,o)),preview:i?await s(l.join(e,i)):0}},z=async e=>{try{return await s(e)}catch{return 0}},x=/(addons.*\:.*\[)/g,_=/^.\s+(\d+\.?\d*) (m?s) for manager and (\d+\.?\d*) (m?s) for preview/m,D=/^.\s+(\d+\.?\d*) (m?s) for preview/m,E=console,R=(e,t)=>{if("ms"===t)return 1e6*parseFloat(e);if("s"===t)return 1e9*parseFloat(e);throw new Error("Unexpected unit of time "+t)},q=JSON.parse(process.env.GCP_CREDENTIALS||"{}"),P="true"===process.env.SB_BENCH_UPLOAD,{CIRCLE_BRANCH:C,CIRCLE_SHA1:T}=process.env,W=e=>{const t=o.sync("git",e,{stdio:"pipe"});if(t.error)throw t.error;return t.output.join("\n").trim()},F=(e,t)=>"object"==typeof e?p(e,e=>F(e,t)):t(e),A=e=>Math.round(e/1e6),M=e=>Math.round(e/1024);exports.main=async()=>{r.arguments("[installCommand]"),r.option("-l, --label <label>","Save as <label>.csv/json and upload with <label> if SB_BENCH_UPLOAD is true","bench"),r.option("-e, --extra-flags <flags>",'Run storybook with extra flags (e.g. "--no-dll")',""),r.option("--no-install","Do not measure storybook install time"),r.option("--no-start","Do not measure storybook start time"),r.option("--no-browse","Do not measure storybook browse time"),r.parse(process.argv),r.install&&!r.args.length&&r.help();const{label:e,extraFlags:g,install:h,start:f,browse:N}=r,B=r.args[0],H=g.length>0?g.split(" "):[],L=await(async({installCommand:e,label:r,extraFlags:u,benchmarks:g})=>{await(async()=>{c.sync("storybook-static")})();const h=(f={install:g.install?await(async e=>{if(console.log("measuring install"),!e)return console.warn("No install command provided"),{size:{total:0},time:{total:0}};const t=await s("node_modules");i.Tick.wrap((function(t){const[r,...a]=e.split(" ");o.sync(r,a,{stdio:"inherit"}),t()}));const r=await s("node_modules");return await(async()=>{let e=["add","@storybook/addon-bench@next","--dev"];(()=>{const e=o.sync("yarn",["--version"]);if(0!==e.status)throw new Error("๐งถ Yarn must be installed to run '@storybook/bench'");const t=e.output.toString().replace(/,/g,"").replace(/"/g,"");return/^1\.+/.test(t)})()&&e.push("-W"),o.sync("yarn",e,{stdio:"inherit"});const t=["js","cjs","mjs","ts"].map(e=>".storybook/main."+e).find(e=>a.existsSync(e));if(!t)throw new Error("No main.js found!");const r=a.readFileSync(t).toString();if(!r.includes("@storybook/addon-bench")){const e=(e=>e.split("\n").map(e=>e.replace(x,'$1 "@storybook/addon-bench",')).join("\n"))(r);a.writeFileSync(t,e)}})(),{size:{total:r-t},time:{total:i.timers.install.duration()}}})(e):{},start:g.start?await(async e=>{let t;console.log("measuring start-storybook");const r=new Promise(e=>{t=e});let a;const i=new Promise(e=>{a=e}),s=y(),n=o.spawn("yarn",["storybook","-p",9999..toString(),"--ci",...e],{stdio:["inherit","pipe","inherit"]});let l,c=-1,w=-1;n.stdout.on("data",e=>{const r=(e=>{const t=_.exec(e);if(t)return{manager:R(t[1],t[2]),preview:R(t[3],t[4])};const r=D.exec(e);return r?{manager:0,preview:R(r[1],r[2])}:void 0})(e.toString());if(r){const{manager:e,preview:a}=r;w=a,c=e,t()}}),n.on("exit",()=>{E.log("closing start-storybook"),a()});const d=await m.chromium.launch({args:b});l=await v(s,async()=>{E.log("killing start-storybook"),n.kill(),E.log("stopping stats server"),await l.stop(),E.log("closing browser"),await d.close()}),await r;const u=await d.newPage();return await u.goto("http://localhost:9999/"),await i,{time:{managerWebpack:c,previewWebpack:w,...s.time},size:{}}})(u):{},...g.browse?await(async e=>{let t;console.log("measuring build-storybook"),i.Tick.wrap((function(t){o.sync("yarn",["build-storybook",...e],{stdio:"inherit"}),t()}));const r=new Promise((e,r)=>{t=e,setTimeout(r,4e4)}),a=y(),c=await m.chromium.launch({args:b}),u=await(async()=>{const e=new w.Server({host:"localhost",port:9899});return await e.register(d),e.route({method:"GET",path:"/{param*}",handler:async(e,t)=>{const r=l.join(process.cwd(),"storybook-static",e.path);return t.file(r,{confine:!1})}}),await e.start(),console.log("Static server:",e.info.uri),e})();let p;p=await v(a,async()=>{k.log("resolving browse"),t(),k.log("stopping stats server"),await p.stop(),k.log("stopping static server"),await u.stop(),k.log("closing browser"),await c.close()});const g=await c.newPage();await g.goto("http://localhost:9899/index.html"),await r;const h={time:{build:i.timers.build.duration()},size:{}},f=await(async e=>{const t=S((await n.readFile(l.join(e,"iframe.html"))).toString()),r=S((await n.readFile(l.join(e,"index.html"))).toString()),[a,i,o,s,c]=await Promise.all([j(e,"main",t,r),j(e,"runtime",t,r),j(e,"vendors",t,r),z(l.join(e,"sb_dll","storybook_docs_dll.js")),z(l.join(e,"sb_dll","storybook_ui_dll.js"))]);return{manager:{total:a.manager+i.manager+o.manager,main:a.manager,runtime:i.manager,vendors:o.manager,uiDll:c},preview:{total:a.preview+i.preview+o.preview,main:a.preview,runtime:i.preview,vendors:o.preview,docsDll:s}}})("storybook-static");return{build:h,browse:{size:{total:await s("storybook-static"),...f},time:a.time}}})(u):{build:{},browse:{}}},p(f,e=>({time:F(e.time,A),size:F(e.size,M)})));var f;return await(async(e,r)=>{const i=await t(e);a.writeFileSync(r+".csv",i),a.writeFileSync(r+".json",JSON.stringify(e))})(h,r),h})({installCommand:B,label:e,extraFlags:H,benchmarks:{install:h,start:f,browse:N}});P&&await(async({install:e,start:t,build:r,browse:a},i)=>{console.log("uploading to label",i);const o={branch:C||W(["rev-parse","--abbrev-ref","HEAD"]),commit:T||W(["rev-parse","HEAD"]),timestamp:(new Date).toISOString(),label:i,installTime:e.time.total,installSize:e.size.total,startManagerBuild:t.time.managerWebpack,startPreviewBuild:t.time.previewWebpack,startManagerRender:t.time.managerRender,startPreviewRender:t.time.previewRender,buildTime:r.time.build,browseManagerRender:a.time.managerRender,browsePreviewRender:a.time.previewRender,browseSizeTotal:a.size.total,browseSizeManagerTotal:a.size.manager.total,browseSizeManagerVendors:a.size.manager.vendors,browseSizeManagerUiDll:a.size.manager.uiDll,browseSizePreviewTotal:a.size.preview.total,browseSizePreviewVendors:a.size.preview.vendors,browseSizePreviewDocsDll:a.size.preview.docsDll},s=new u.BigQuery({projectId:q.project_id,credentials:q}).dataset("benchmark_results").table("bench");await s.insert([o])})(L,e)}; | ||
//# sourceMappingURL=bench.cjs.production.min.js.map |
{ | ||
"name": "@storybook/bench", | ||
"version": "1.0.0-next.2", | ||
"version": "1.0.0-next.3", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "author": "Michael Shilman", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
101695