Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 0 additions & 94 deletions code/.storybook/bench.stories.tsx

This file was deleted.

81 changes: 81 additions & 0 deletions code/.storybook/bench/bench.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import React from 'react';

import type { Meta } from '@storybook/react-vite';

import { safeMetafileArg } from '../../../scripts/bench/safe-args';

// @ts-expect-error - TS doesn't know about import.meta.glob from Vite
const allMetafiles = import.meta.glob(['../../bench/esbuild-metafiles/**/*.json'], {
import: 'default',
});

export default {
title: 'Bench',
parameters: {
layout: 'fullscreen',
chromatic: { disableSnapshot: true },
},
args: {
// default to the core/node.json metafile
metafile: safeMetafileArg(
Object.keys(allMetafiles).find((path) => path.includes('/core/node.json'))!
),
},
argTypes: {
metafile: {
options: Object.keys(allMetafiles).map(safeMetafileArg).sort(),
mapping: Object.fromEntries(
Object.keys(allMetafiles).map((path) => [safeMetafileArg(path), path])
),
control: {
type: 'select',
labels: Object.fromEntries(
Object.keys(allMetafiles).map((path) => {
const [, dirname, subEntry] = /esbuild-metafiles\/(.+)\/(.+).json/.exec(path)!;

// most metafile directories are named exactly like their package name within the @storybook scope
let packageName = '@storybook/' + dirname;

// but some are not, so we need to map them to the correct package name
switch (dirname) {
case 'core': {
packageName = 'storybook';
break;
}
case 'eslint-plugin':
packageName = 'eslint-plugin-storybook';
break;
case 'create-storybook':
case 'storybook-addon-pseudo-states':
packageName = dirname;
}

return [safeMetafileArg(path), `${packageName} - ${subEntry}`];
})
),
},
},
},
beforeEach: async ({ args }) => {
if (!args.metafile) {
globalThis.metafile = undefined;
return;
}
const metafile = await allMetafiles[args.metafile]();
// this is read by the bundle-analyzer iframe via parent.metafile, in bundle-analyzer/index.js
globalThis.metafile = JSON.stringify(metafile);
Comment on lines +64 to +66

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the diff is annoying because the file was moved, this is the important new part

Comment thread
JReinhold marked this conversation as resolved.
Comment thread
JReinhold marked this conversation as resolved.
},
render: (args) => {
return (
<iframe
src="/bundle-analyzer/index.html"
style={{ border: 'none', width: '100%', height: '100vh' }}
key={args.metafile} // force re-render on args change
/>
);
},
} satisfies Meta;

export const ESBuildAnalyzer = {
name: 'ESBuild Metafiles',
};
Loading