diff --git a/.circleci/config.yml b/.circleci/config.yml
index 72f3bf9dc225..95ff7dd6304a 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -154,6 +154,8 @@ jobs:
cd code
yarn local-registry --publish
- report-workflow-on-failure
+ - store_artifacts:
+ path: code/bench/esbuild-metafiles
- save_cache:
name: Save Yarn cache
key: build-yarn-2-cache-v4--{{ checksum "code/yarn.lock" }}--{{ checksum "scripts/yarn.lock" }}
@@ -164,6 +166,7 @@ jobs:
paths:
- code/node_modules
- scripts/node_modules
+ - code/bench
- code/examples
- code/node_modules
- code/addons
diff --git a/.gitignore b/.gitignore
index acfc54475076..f0ad86dc47c4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,6 +12,7 @@ test-results
/repros
/sandbox
/bench
+/code/bench
.verdaccio-cache
.next
/.npmrc
diff --git a/code/.storybook/bench.stories.tsx b/code/.storybook/bench.stories.tsx
new file mode 100644
index 000000000000..5f59a0550eb4
--- /dev/null
+++ b/code/.storybook/bench.stories.tsx
@@ -0,0 +1,89 @@
+import React from 'react';
+
+import type { Meta } from '@storybook/react';
+
+// @ts-expect-error - TS doesn't know about import.meta.glob from Vite
+const allMetafiles = import.meta.glob([
+ '../bench/esbuild-metafiles/**/*.json',
+ // the core metafile is too big to be loaded automatically in the iframe
+ '!../bench/esbuild-metafiles/core/core.json',
+]);
+
+const METAFILES_DIR = '../bench/esbuild-metafiles/';
+const PACKAGES_WITHOUT_ORG = ['storybook', 'sb', 'create-storybook'];
+
+// allows the metafile path to be used in the URL hash
+const safeMetafileArg = (path: string) =>
+ path
+ .replace(METAFILES_DIR, '')
+ .replaceAll('/', '__')
+ .replace(/(\w*).json/, '$1');
+
+export default {
+ title: 'Bench',
+ parameters: {
+ layout: 'fullscreen',
+ chromatic: { disableSnapshot: true },
+ },
+ args: {
+ metafile: safeMetafileArg(Object.keys(allMetafiles)[0]),
+ },
+ argTypes: {
+ metafile: {
+ options: Object.keys(allMetafiles).concat('core - core').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)!;
+ const pkgName = PACKAGES_WITHOUT_ORG.includes(dirName)
+ ? dirName
+ : `@storybook/${dirName}`;
+
+ return [
+ safeMetafileArg(path),
+ subEntry !== 'metafile' ? `${pkgName} - ${subEntry}` : pkgName,
+ ];
+ })
+ .concat([['core - core', '@storybook/core - core - TOO BIG PLEASE UPLOAD MANUALLY']])
+ ),
+ },
+ },
+ },
+ loaders: [
+ async ({ args }) => {
+ if (!args.metafile) {
+ return;
+ }
+ let metafile;
+ try {
+ metafile = await allMetafiles[args.metafile]();
+ } catch (e) {
+ return;
+ }
+ const encodedMetafile = btoa(JSON.stringify(metafile));
+ return { encodedMetafile };
+ },
+ ],
+ render: (args, { loaded }) => {
+ const { encodedMetafile = '' } = loaded ?? {};
+
+ return (
+
+ );
+ },
+} satisfies Meta;
+
+export const ESBuildAnalyzer = {
+ name: 'ESBuild Metafiles',
+};
diff --git a/code/.storybook/main.ts b/code/.storybook/main.ts
index a4cedde66608..5edddcd690a7 100644
--- a/code/.storybook/main.ts
+++ b/code/.storybook/main.ts
@@ -7,6 +7,7 @@ const managerApiPath = join(__dirname, '../core/src/manager-api');
const config: StorybookConfig = {
stories: [
+ './*.stories.@(js|jsx|ts|tsx)',
{
directory: '../core/template/stories',
titlePrefix: 'core',
diff --git a/code/addons/a11y/project.json b/code/addons/a11y/project.json
index 6f6ae5001641..e27e525561ad 100644
--- a/code/addons/a11y/project.json
+++ b/code/addons/a11y/project.json
@@ -1,5 +1,5 @@
{
- "name": "a11y",
+ "name": "addon-a11y",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "library",
"targets": {
diff --git a/code/addons/actions/project.json b/code/addons/actions/project.json
index 3c4ef7dc79d6..67552f132064 100644
--- a/code/addons/actions/project.json
+++ b/code/addons/actions/project.json
@@ -1,5 +1,5 @@
{
- "name": "actions",
+ "name": "addon-actions",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "library",
"targets": {
diff --git a/code/addons/backgrounds/project.json b/code/addons/backgrounds/project.json
index 0ad6e6300a52..b1de9e2ae100 100644
--- a/code/addons/backgrounds/project.json
+++ b/code/addons/backgrounds/project.json
@@ -1,5 +1,5 @@
{
- "name": "backgrounds",
+ "name": "addon-backgrounds",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "library",
"targets": {
diff --git a/code/addons/controls/project.json b/code/addons/controls/project.json
index e143e289fe2f..e8c9dfeeca76 100644
--- a/code/addons/controls/project.json
+++ b/code/addons/controls/project.json
@@ -1,5 +1,5 @@
{
- "name": "controls",
+ "name": "addon-controls",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "library",
"targets": {
diff --git a/code/addons/docs/project.json b/code/addons/docs/project.json
index 04ab0c7d4701..03194c3a0503 100644
--- a/code/addons/docs/project.json
+++ b/code/addons/docs/project.json
@@ -1,5 +1,5 @@
{
- "name": "docs",
+ "name": "addon-docs",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "library",
"targets": {
diff --git a/code/addons/essentials/project.json b/code/addons/essentials/project.json
index 74274d0bb5e7..f354a1840421 100644
--- a/code/addons/essentials/project.json
+++ b/code/addons/essentials/project.json
@@ -1,5 +1,5 @@
{
- "name": "essentials",
+ "name": "addon-essentials",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "library",
"targets": {
diff --git a/code/addons/gfm/project.json b/code/addons/gfm/project.json
index bb5861ab0d11..fea7870c840b 100644
--- a/code/addons/gfm/project.json
+++ b/code/addons/gfm/project.json
@@ -1,5 +1,5 @@
{
- "name": "gfm",
+ "name": "addon-gfm",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "library",
"targets": {
diff --git a/code/addons/highlight/project.json b/code/addons/highlight/project.json
index 85847caedb9b..66b5104c0618 100644
--- a/code/addons/highlight/project.json
+++ b/code/addons/highlight/project.json
@@ -1,5 +1,5 @@
{
- "name": "highlight",
+ "name": "addon-highlight",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "library",
"targets": {
diff --git a/code/addons/interactions/project.json b/code/addons/interactions/project.json
index 2dbab1cc3233..d2fd1ee2dab5 100644
--- a/code/addons/interactions/project.json
+++ b/code/addons/interactions/project.json
@@ -1,5 +1,5 @@
{
- "name": "interactions",
+ "name": "addon-interactions",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "library",
"targets": {
diff --git a/code/addons/jest/project.json b/code/addons/jest/project.json
index e7852e6415fc..226ea5597330 100644
--- a/code/addons/jest/project.json
+++ b/code/addons/jest/project.json
@@ -1,5 +1,5 @@
{
- "name": "jest",
+ "name": "addon-jest",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "library",
"targets": {
diff --git a/code/addons/links/project.json b/code/addons/links/project.json
index 60e9238ad5ad..7f246ffb677b 100644
--- a/code/addons/links/project.json
+++ b/code/addons/links/project.json
@@ -1,5 +1,5 @@
{
- "name": "links",
+ "name": "addon-links",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "library",
"targets": {
diff --git a/code/addons/measure/project.json b/code/addons/measure/project.json
index deaa4529c04d..60e8867d2e88 100644
--- a/code/addons/measure/project.json
+++ b/code/addons/measure/project.json
@@ -1,5 +1,5 @@
{
- "name": "measure",
+ "name": "addon-measure",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "library",
"targets": {
diff --git a/code/addons/onboarding/project.json b/code/addons/onboarding/project.json
index f2f83ffd6d64..75697db7494a 100644
--- a/code/addons/onboarding/project.json
+++ b/code/addons/onboarding/project.json
@@ -1,5 +1,5 @@
{
- "name": "onboarding",
+ "name": "addon-onboarding",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "library",
"targets": {
diff --git a/code/addons/outline/project.json b/code/addons/outline/project.json
index 5183adf1235e..ed8081003447 100644
--- a/code/addons/outline/project.json
+++ b/code/addons/outline/project.json
@@ -1,5 +1,5 @@
{
- "name": "outline",
+ "name": "addon-outline",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "library",
"targets": {
diff --git a/code/addons/storysource/project.json b/code/addons/storysource/project.json
index 9ebd0d3c0829..21fe2fc0731b 100644
--- a/code/addons/storysource/project.json
+++ b/code/addons/storysource/project.json
@@ -1,5 +1,5 @@
{
- "name": "storysource",
+ "name": "addon-storysource",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "library",
"targets": {
diff --git a/code/addons/test/project.json b/code/addons/test/project.json
index 96314d1efc94..c23ed17fc57b 100644
--- a/code/addons/test/project.json
+++ b/code/addons/test/project.json
@@ -1,5 +1,5 @@
{
- "name": "addon-test",
+ "name": "experimental-addon-test",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "library",
"targets": {
diff --git a/code/addons/themes/project.json b/code/addons/themes/project.json
index ea17cd02b7b9..48d062a5ffe8 100644
--- a/code/addons/themes/project.json
+++ b/code/addons/themes/project.json
@@ -1,5 +1,5 @@
{
- "name": "themes",
+ "name": "addon-themes",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"targets": {
"build": {}
diff --git a/code/addons/toolbars/project.json b/code/addons/toolbars/project.json
index aa7476d22fd8..382c8c0ed590 100644
--- a/code/addons/toolbars/project.json
+++ b/code/addons/toolbars/project.json
@@ -1,5 +1,5 @@
{
- "name": "toolbars",
+ "name": "addon-toolbars",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "library",
"targets": {
diff --git a/code/addons/viewport/project.json b/code/addons/viewport/project.json
index 94fc39e648d0..3d5b204b276a 100644
--- a/code/addons/viewport/project.json
+++ b/code/addons/viewport/project.json
@@ -1,5 +1,5 @@
{
- "name": "viewport",
+ "name": "addon-viewport",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "library",
"targets": {
diff --git a/code/core/scripts/prep.ts b/code/core/scripts/prep.ts
index 20c979ebd9aa..b01a8603ba3d 100644
--- a/code/core/scripts/prep.ts
+++ b/code/core/scripts/prep.ts
@@ -3,6 +3,8 @@ import { existsSync, mkdirSync, watch } from 'node:fs';
import { mkdir, rm, writeFile } from 'node:fs/promises';
import { dirname, join } from 'node:path';
+import type { Metafile } from 'esbuild';
+
import {
chalk,
dedent,
@@ -306,27 +308,58 @@ async function run() {
console.log(`compiled ${chalk.cyan(filename)}`);
});
} else {
- await Promise.all(
- compile.map(async (context, index) => {
- const out = await context.rebuild();
+ // repo root/bench/esbuild-metafiles/core
+ const metafilesDir = join(__dirname, '..', '..', 'bench', 'esbuild-metafiles', 'core');
+ if (existsSync(metafilesDir)) {
+ await rm(metafilesDir, { recursive: true });
+ }
+ await mkdir(metafilesDir, { recursive: true });
+
+ const outputs = await Promise.all(
+ compile.map(async (context) => {
+ const output = await context.rebuild();
await context.dispose();
- if (out.metafile) {
- const { outputs } = out.metafile;
- const keys = Object.keys(outputs);
- const format = keys.every((key) => key.endsWith('.js')) ? 'esm' : 'cjs';
- const outName =
- keys.length === 1 ? dirname(keys[0]).replace('dist/', '') : `meta-${format}-${index}`;
-
- if (!existsSync('report')) {
- mkdirSync('report');
- }
- await writeFile(`report/${outName}.json`, JSON.stringify(out.metafile, null, 2));
- await writeFile(
- `report/${outName}.txt`,
- await esbuild.analyzeMetafile(out.metafile, { color: false, verbose: false })
- );
- }
+ return output;
+ })
+ );
+
+ const metafileByModule: Record = {};
+
+ for (const currentOutput of outputs) {
+ if (!currentOutput.metafile) {
+ continue;
+ }
+
+ const keys = Object.keys(currentOutput.metafile.outputs);
+ const moduleName = keys.length === 1 ? dirname(keys[0]).replace('dist/', '') : 'core';
+
+ const existingMetafile = metafileByModule[moduleName];
+
+ if (existingMetafile) {
+ existingMetafile.inputs = {
+ ...existingMetafile.inputs,
+ ...currentOutput.metafile.inputs,
+ };
+ existingMetafile.outputs = {
+ ...existingMetafile.outputs,
+ ...currentOutput.metafile.outputs,
+ };
+ } else {
+ metafileByModule[moduleName] = currentOutput.metafile;
+ }
+ }
+
+ await Promise.all(
+ Object.entries(metafileByModule).map(async ([moduleName, metafile]) => {
+ await writeFile(
+ join(metafilesDir, `${moduleName}.json`),
+ JSON.stringify(metafile, null, 2)
+ );
+ await writeFile(
+ join(metafilesDir, `${moduleName}.txt`),
+ await esbuild.analyzeMetafile(metafile, { color: false, verbose: false })
+ );
})
);
}
diff --git a/code/lib/cli-sb/project.json b/code/lib/cli-sb/project.json
index efaba5c541b2..25f5e9e0ebb9 100644
--- a/code/lib/cli-sb/project.json
+++ b/code/lib/cli-sb/project.json
@@ -1,5 +1,5 @@
{
- "name": "cli-sb",
+ "name": "sb",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "library",
"targets": {}
diff --git a/code/lib/cli-storybook/project.json b/code/lib/cli-storybook/project.json
index 229b547bb854..82cebd8431b3 100644
--- a/code/lib/cli-storybook/project.json
+++ b/code/lib/cli-storybook/project.json
@@ -1,5 +1,5 @@
{
- "name": "cli-storybook",
+ "name": "cli",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "library",
"targets": {
diff --git a/code/lib/cli/project.json b/code/lib/cli/project.json
index 82cebd8431b3..4f06674e2e03 100644
--- a/code/lib/cli/project.json
+++ b/code/lib/cli/project.json
@@ -1,5 +1,5 @@
{
- "name": "cli",
+ "name": "storybook",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "library",
"targets": {
diff --git a/code/lib/instrumenter/project.json b/code/lib/instrumenter/project.json
index 3ecdad88a0dd..dd7cc79ecbe4 100644
--- a/code/lib/instrumenter/project.json
+++ b/code/lib/instrumenter/project.json
@@ -1,4 +1,5 @@
{
+ "name": "instrumenter",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "library",
"targets": {
diff --git a/code/lib/test/project.json b/code/lib/test/project.json
index 3ecdad88a0dd..1302a230f1e1 100644
--- a/code/lib/test/project.json
+++ b/code/lib/test/project.json
@@ -1,4 +1,5 @@
{
+ "name": "test",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "library",
"targets": {
diff --git a/code/nx.json b/code/nx.json
index 12070cbb8d4e..2f726cea4387 100644
--- a/code/nx.json
+++ b/code/nx.json
@@ -52,7 +52,7 @@
"{workspaceRoot}/../scripts/prepare/{bundle,addon-bundle,esm-bundle}.ts"
],
"dependsOn": ["^build"],
- "outputs": ["{projectRoot}/dist"],
+ "outputs": ["{projectRoot}/dist", "{workspaceRoot}/bench/esbuild-metafiles/{projectName}"],
"cache": true
},
"test": {
diff --git a/code/sandbox/angular-cli-15-ts/project.json b/code/sandbox/angular-cli-15-ts/project.json
index b59d1e58d99f..d2d595560d2a 100644
--- a/code/sandbox/angular-cli-15-ts/project.json
+++ b/code/sandbox/angular-cli-15-ts/project.json
@@ -3,12 +3,12 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": [
- "cli",
+ "storybook",
"core",
- "essentials",
- "interactions",
- "links",
- "onboarding",
+ "addon-essentials",
+ "addon-interactions",
+ "addon-links",
+ "addon-onboarding",
"blocks",
"angular"
],
diff --git a/code/sandbox/angular-cli-default-ts/project.json b/code/sandbox/angular-cli-default-ts/project.json
index 76d3d5738544..cb48bbc83e0e 100644
--- a/code/sandbox/angular-cli-default-ts/project.json
+++ b/code/sandbox/angular-cli-default-ts/project.json
@@ -3,12 +3,12 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": [
- "cli",
+ "storybook",
"core",
- "essentials",
- "interactions",
- "links",
- "onboarding",
+ "addon-essentials",
+ "addon-interactions",
+ "addon-links",
+ "addon-onboarding",
"blocks",
"angular"
],
diff --git a/code/sandbox/angular-cli-prerelease/project.json b/code/sandbox/angular-cli-prerelease/project.json
index e07d7448e0eb..4433e7dde157 100644
--- a/code/sandbox/angular-cli-prerelease/project.json
+++ b/code/sandbox/angular-cli-prerelease/project.json
@@ -3,12 +3,12 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": [
- "cli",
+ "storybook",
"core",
- "essentials",
- "interactions",
- "links",
- "onboarding",
+ "addon-essentials",
+ "addon-interactions",
+ "addon-links",
+ "addon-onboarding",
"blocks",
"angular"
],
diff --git a/code/sandbox/bench-react-vite-default-ts-nodocs/project.json b/code/sandbox/bench-react-vite-default-ts-nodocs/project.json
index 3c879e9894c6..e0ed20e23930 100644
--- a/code/sandbox/bench-react-vite-default-ts-nodocs/project.json
+++ b/code/sandbox/bench-react-vite-default-ts-nodocs/project.json
@@ -3,12 +3,12 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": [
- "cli",
+ "storybook",
"core",
- "essentials",
- "interactions",
- "links",
- "onboarding",
+ "addon-essentials",
+ "addon-interactions",
+ "addon-links",
+ "addon-onboarding",
"blocks",
"react-vite"
],
diff --git a/code/sandbox/bench-react-vite-default-ts-test-build/project.json b/code/sandbox/bench-react-vite-default-ts-test-build/project.json
index ce151efd582d..5e44f6ba14ce 100644
--- a/code/sandbox/bench-react-vite-default-ts-test-build/project.json
+++ b/code/sandbox/bench-react-vite-default-ts-test-build/project.json
@@ -3,12 +3,12 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": [
- "cli",
+ "storybook",
"core",
- "essentials",
- "interactions",
- "links",
- "onboarding",
+ "addon-essentials",
+ "addon-interactions",
+ "addon-links",
+ "addon-onboarding",
"blocks",
"react-vite"
],
diff --git a/code/sandbox/bench-react-vite-default-ts/project.json b/code/sandbox/bench-react-vite-default-ts/project.json
index 07766ae7da96..a59cb05cc369 100644
--- a/code/sandbox/bench-react-vite-default-ts/project.json
+++ b/code/sandbox/bench-react-vite-default-ts/project.json
@@ -3,12 +3,12 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": [
- "cli",
+ "storybook",
"core",
- "essentials",
- "interactions",
- "links",
- "onboarding",
+ "addon-essentials",
+ "addon-interactions",
+ "addon-links",
+ "addon-onboarding",
"blocks",
"react-vite"
],
diff --git a/code/sandbox/bench-react-webpack-18-ts-test-build/project.json b/code/sandbox/bench-react-webpack-18-ts-test-build/project.json
index 45744cfd7fc0..647d78878fd3 100644
--- a/code/sandbox/bench-react-webpack-18-ts-test-build/project.json
+++ b/code/sandbox/bench-react-webpack-18-ts-test-build/project.json
@@ -3,12 +3,12 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": [
- "cli",
+ "storybook",
"core",
- "essentials",
- "interactions",
- "links",
- "onboarding",
+ "addon-essentials",
+ "addon-interactions",
+ "addon-links",
+ "addon-onboarding",
"blocks",
"react-webpack5"
],
diff --git a/code/sandbox/bench-react-webpack-18-ts/project.json b/code/sandbox/bench-react-webpack-18-ts/project.json
index 91958a205f40..2825bb2831d2 100644
--- a/code/sandbox/bench-react-webpack-18-ts/project.json
+++ b/code/sandbox/bench-react-webpack-18-ts/project.json
@@ -3,12 +3,12 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": [
- "cli",
+ "storybook",
"core",
- "essentials",
- "interactions",
- "links",
- "onboarding",
+ "addon-essentials",
+ "addon-interactions",
+ "addon-links",
+ "addon-onboarding",
"blocks",
"react-webpack5"
],
diff --git a/code/sandbox/cra-default-js/project.json b/code/sandbox/cra-default-js/project.json
index e3565c634036..a8febc5d3b00 100644
--- a/code/sandbox/cra-default-js/project.json
+++ b/code/sandbox/cra-default-js/project.json
@@ -3,12 +3,12 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": [
- "cli",
+ "storybook",
"core",
- "essentials",
- "interactions",
- "links",
- "onboarding",
+ "addon-essentials",
+ "addon-interactions",
+ "addon-links",
+ "addon-onboarding",
"blocks",
"react-webpack5"
],
diff --git a/code/sandbox/cra-default-ts/project.json b/code/sandbox/cra-default-ts/project.json
index d3ac6861159f..b51b71aa0940 100644
--- a/code/sandbox/cra-default-ts/project.json
+++ b/code/sandbox/cra-default-ts/project.json
@@ -3,12 +3,12 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": [
- "cli",
+ "storybook",
"core",
- "essentials",
- "interactions",
- "links",
- "onboarding",
+ "addon-essentials",
+ "addon-interactions",
+ "addon-links",
+ "addon-onboarding",
"blocks",
"react-webpack5"
],
diff --git a/code/sandbox/ember-3-js/project.json b/code/sandbox/ember-3-js/project.json
index e31e6d1ebbc4..068515be75b2 100644
--- a/code/sandbox/ember-3-js/project.json
+++ b/code/sandbox/ember-3-js/project.json
@@ -3,12 +3,12 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": [
- "cli",
+ "storybook",
"core",
- "essentials",
- "interactions",
- "links",
- "onboarding",
+ "addon-essentials",
+ "addon-interactions",
+ "addon-links",
+ "addon-onboarding",
"blocks",
"ember"
],
diff --git a/code/sandbox/ember-default-js/project.json b/code/sandbox/ember-default-js/project.json
index f63dfb0f2d3b..81f91494ac2a 100644
--- a/code/sandbox/ember-default-js/project.json
+++ b/code/sandbox/ember-default-js/project.json
@@ -3,12 +3,12 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": [
- "cli",
+ "storybook",
"core",
- "essentials",
- "interactions",
- "links",
- "onboarding",
+ "addon-essentials",
+ "addon-interactions",
+ "addon-links",
+ "addon-onboarding",
"blocks",
"ember"
],
diff --git a/code/sandbox/html-vite-default-js/project.json b/code/sandbox/html-vite-default-js/project.json
index f7c873967190..9363e37e0b07 100644
--- a/code/sandbox/html-vite-default-js/project.json
+++ b/code/sandbox/html-vite-default-js/project.json
@@ -3,12 +3,12 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": [
- "cli",
+ "storybook",
"core",
- "essentials",
- "interactions",
- "links",
- "onboarding",
+ "addon-essentials",
+ "addon-interactions",
+ "addon-links",
+ "addon-onboarding",
"blocks",
"html-vite"
],
diff --git a/code/sandbox/html-vite-default-ts/project.json b/code/sandbox/html-vite-default-ts/project.json
index e297ef74eba4..d816dd3fbd29 100644
--- a/code/sandbox/html-vite-default-ts/project.json
+++ b/code/sandbox/html-vite-default-ts/project.json
@@ -3,12 +3,12 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": [
- "cli",
+ "storybook",
"core",
- "essentials",
- "interactions",
- "links",
- "onboarding",
+ "addon-essentials",
+ "addon-interactions",
+ "addon-links",
+ "addon-onboarding",
"blocks",
"html-vite"
],
diff --git a/code/sandbox/html-webpack-default/project.json b/code/sandbox/html-webpack-default/project.json
index 44dfca1ab5b5..466b55828a54 100644
--- a/code/sandbox/html-webpack-default/project.json
+++ b/code/sandbox/html-webpack-default/project.json
@@ -3,12 +3,12 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": [
- "cli",
+ "storybook",
"core",
- "essentials",
- "interactions",
- "links",
- "onboarding",
+ "addon-essentials",
+ "addon-interactions",
+ "addon-links",
+ "addon-onboarding",
"blocks",
"html-webpack5"
],
diff --git a/code/sandbox/internal-react16-webpack/project.json b/code/sandbox/internal-react16-webpack/project.json
index 909c0797144b..a2164412649b 100644
--- a/code/sandbox/internal-react16-webpack/project.json
+++ b/code/sandbox/internal-react16-webpack/project.json
@@ -3,12 +3,12 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": [
- "cli",
+ "storybook",
"core",
- "essentials",
- "interactions",
- "links",
- "onboarding",
+ "addon-essentials",
+ "addon-interactions",
+ "addon-links",
+ "addon-onboarding",
"blocks",
"react-webpack5"
],
diff --git a/code/sandbox/internal-react18-webpack-babel/project.json b/code/sandbox/internal-react18-webpack-babel/project.json
index 6d0d1545bd57..e1585cc8ba0b 100644
--- a/code/sandbox/internal-react18-webpack-babel/project.json
+++ b/code/sandbox/internal-react18-webpack-babel/project.json
@@ -3,12 +3,12 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": [
- "cli",
+ "storybook",
"core",
- "essentials",
- "interactions",
- "links",
- "onboarding",
+ "addon-essentials",
+ "addon-interactions",
+ "addon-links",
+ "addon-onboarding",
"blocks",
"react-webpack5"
],
diff --git a/code/sandbox/internal-server-webpack5/project.json b/code/sandbox/internal-server-webpack5/project.json
index b1e2f7adfaf7..51b572402699 100644
--- a/code/sandbox/internal-server-webpack5/project.json
+++ b/code/sandbox/internal-server-webpack5/project.json
@@ -3,12 +3,12 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": [
- "cli",
+ "storybook",
"core",
- "essentials",
- "interactions",
- "links",
- "onboarding",
+ "addon-essentials",
+ "addon-interactions",
+ "addon-links",
+ "addon-onboarding",
"blocks",
"server-webpack5"
],
diff --git a/code/sandbox/lit-vite-default-js/project.json b/code/sandbox/lit-vite-default-js/project.json
index 659690873d7d..22bf1065c982 100644
--- a/code/sandbox/lit-vite-default-js/project.json
+++ b/code/sandbox/lit-vite-default-js/project.json
@@ -3,12 +3,12 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": [
- "cli",
+ "storybook",
"core",
- "essentials",
- "interactions",
- "links",
- "onboarding",
+ "addon-essentials",
+ "addon-interactions",
+ "addon-links",
+ "addon-onboarding",
"blocks",
"web-components-vite"
],
diff --git a/code/sandbox/lit-vite-default-ts/project.json b/code/sandbox/lit-vite-default-ts/project.json
index 273084b0d96f..978833395968 100644
--- a/code/sandbox/lit-vite-default-ts/project.json
+++ b/code/sandbox/lit-vite-default-ts/project.json
@@ -3,12 +3,12 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": [
- "cli",
+ "storybook",
"core",
- "essentials",
- "interactions",
- "links",
- "onboarding",
+ "addon-essentials",
+ "addon-interactions",
+ "addon-links",
+ "addon-onboarding",
"blocks",
"web-components-vite"
],
diff --git a/code/sandbox/nextjs-13-ts/project.json b/code/sandbox/nextjs-13-ts/project.json
index e06a73e0bc06..d83ef788bf2c 100644
--- a/code/sandbox/nextjs-13-ts/project.json
+++ b/code/sandbox/nextjs-13-ts/project.json
@@ -3,12 +3,12 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": [
- "cli",
+ "storybook",
"core",
- "essentials",
- "interactions",
- "links",
- "onboarding",
+ "addon-essentials",
+ "addon-interactions",
+ "addon-links",
+ "addon-onboarding",
"blocks",
"nextjs"
],
diff --git a/code/sandbox/nextjs-default-js/project.json b/code/sandbox/nextjs-default-js/project.json
index a7c86faa9f0c..540936cbd268 100644
--- a/code/sandbox/nextjs-default-js/project.json
+++ b/code/sandbox/nextjs-default-js/project.json
@@ -3,12 +3,12 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": [
- "cli",
+ "storybook",
"core",
- "essentials",
- "interactions",
- "links",
- "onboarding",
+ "addon-essentials",
+ "addon-interactions",
+ "addon-links",
+ "addon-onboarding",
"blocks",
"nextjs"
],
diff --git a/code/sandbox/nextjs-default-ts/project.json b/code/sandbox/nextjs-default-ts/project.json
index feb21dacb48f..5144fc10b9d4 100644
--- a/code/sandbox/nextjs-default-ts/project.json
+++ b/code/sandbox/nextjs-default-ts/project.json
@@ -3,12 +3,12 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": [
- "cli",
+ "storybook",
"core",
- "essentials",
- "interactions",
- "links",
- "onboarding",
+ "addon-essentials",
+ "addon-interactions",
+ "addon-links",
+ "addon-onboarding",
"blocks",
"nextjs"
],
diff --git a/code/sandbox/nextjs-prerelease/project.json b/code/sandbox/nextjs-prerelease/project.json
index 3c7d06c9f0df..9579c10b3928 100644
--- a/code/sandbox/nextjs-prerelease/project.json
+++ b/code/sandbox/nextjs-prerelease/project.json
@@ -3,12 +3,12 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": [
- "cli",
+ "storybook",
"core",
- "essentials",
- "interactions",
- "links",
- "onboarding",
+ "addon-essentials",
+ "addon-interactions",
+ "addon-links",
+ "addon-onboarding",
"blocks",
"nextjs"
],
diff --git a/code/sandbox/preact-vite-default-js/project.json b/code/sandbox/preact-vite-default-js/project.json
index 524fb53a196a..4eb038e5c735 100644
--- a/code/sandbox/preact-vite-default-js/project.json
+++ b/code/sandbox/preact-vite-default-js/project.json
@@ -3,12 +3,12 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": [
- "cli",
+ "storybook",
"core",
- "essentials",
- "interactions",
- "links",
- "onboarding",
+ "addon-essentials",
+ "addon-interactions",
+ "addon-links",
+ "addon-onboarding",
"blocks",
"preact-vite"
],
diff --git a/code/sandbox/preact-vite-default-ts/project.json b/code/sandbox/preact-vite-default-ts/project.json
index 2fffaf2a2153..2c1cdf04e3a4 100644
--- a/code/sandbox/preact-vite-default-ts/project.json
+++ b/code/sandbox/preact-vite-default-ts/project.json
@@ -3,12 +3,12 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": [
- "cli",
+ "storybook",
"core",
- "essentials",
- "interactions",
- "links",
- "onboarding",
+ "addon-essentials",
+ "addon-interactions",
+ "addon-links",
+ "addon-onboarding",
"blocks",
"preact-vite"
],
diff --git a/code/sandbox/qwik-vite-default-ts/project.json b/code/sandbox/qwik-vite-default-ts/project.json
index b354e5f74615..0a1c65c53499 100644
--- a/code/sandbox/qwik-vite-default-ts/project.json
+++ b/code/sandbox/qwik-vite-default-ts/project.json
@@ -3,12 +3,12 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": [
- "cli",
+ "storybook",
"core",
- "essentials",
- "interactions",
- "links",
- "onboarding",
+ "addon-essentials",
+ "addon-interactions",
+ "addon-links",
+ "addon-onboarding",
"blocks"
],
"targets": {
diff --git a/code/sandbox/react-vite-default-js/project.json b/code/sandbox/react-vite-default-js/project.json
index 7f440a312ce0..cc44d8e4a6fa 100644
--- a/code/sandbox/react-vite-default-js/project.json
+++ b/code/sandbox/react-vite-default-js/project.json
@@ -3,12 +3,12 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": [
- "cli",
+ "storybook",
"core",
- "essentials",
- "interactions",
- "links",
- "onboarding",
+ "addon-essentials",
+ "addon-interactions",
+ "addon-links",
+ "addon-onboarding",
"blocks",
"react-vite"
],
diff --git a/code/sandbox/react-vite-default-ts/project.json b/code/sandbox/react-vite-default-ts/project.json
index bea7aa3642b1..25c9b2442a1b 100644
--- a/code/sandbox/react-vite-default-ts/project.json
+++ b/code/sandbox/react-vite-default-ts/project.json
@@ -3,12 +3,12 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": [
- "cli",
+ "storybook",
"core",
- "essentials",
- "interactions",
- "links",
- "onboarding",
+ "addon-essentials",
+ "addon-interactions",
+ "addon-links",
+ "addon-onboarding",
"blocks",
"react-vite"
],
diff --git a/code/sandbox/react-webpack-17-ts/project.json b/code/sandbox/react-webpack-17-ts/project.json
index a9dd4fe427ac..01209a70efa9 100644
--- a/code/sandbox/react-webpack-17-ts/project.json
+++ b/code/sandbox/react-webpack-17-ts/project.json
@@ -3,12 +3,12 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": [
- "cli",
+ "storybook",
"core",
- "essentials",
- "interactions",
- "links",
- "onboarding",
+ "addon-essentials",
+ "addon-interactions",
+ "addon-links",
+ "addon-onboarding",
"blocks",
"react-webpack5"
],
diff --git a/code/sandbox/react-webpack-18-ts/project.json b/code/sandbox/react-webpack-18-ts/project.json
index d95c1a4c4bff..34cae14e059c 100644
--- a/code/sandbox/react-webpack-18-ts/project.json
+++ b/code/sandbox/react-webpack-18-ts/project.json
@@ -3,12 +3,12 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": [
- "cli",
+ "storybook",
"core",
- "essentials",
- "interactions",
- "links",
- "onboarding",
+ "addon-essentials",
+ "addon-interactions",
+ "addon-links",
+ "addon-onboarding",
"blocks",
"react-webpack5"
],
diff --git a/code/sandbox/solid-vite-default-js/project.json b/code/sandbox/solid-vite-default-js/project.json
index 471ad5fe3aa4..7bba5774a7a1 100644
--- a/code/sandbox/solid-vite-default-js/project.json
+++ b/code/sandbox/solid-vite-default-js/project.json
@@ -3,12 +3,12 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": [
- "cli",
+ "storybook",
"core",
- "essentials",
- "interactions",
- "links",
- "onboarding",
+ "addon-essentials",
+ "addon-interactions",
+ "addon-links",
+ "addon-onboarding",
"blocks"
],
"targets": {
diff --git a/code/sandbox/solid-vite-default-ts/project.json b/code/sandbox/solid-vite-default-ts/project.json
index 3b084c7804f1..50d504a77255 100644
--- a/code/sandbox/solid-vite-default-ts/project.json
+++ b/code/sandbox/solid-vite-default-ts/project.json
@@ -3,12 +3,12 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": [
- "cli",
+ "storybook",
"core",
- "essentials",
- "interactions",
- "links",
- "onboarding",
+ "addon-essentials",
+ "addon-interactions",
+ "addon-links",
+ "addon-onboarding",
"blocks"
],
"targets": {
diff --git a/code/sandbox/svelte-kit-prerelease-ts/project.json b/code/sandbox/svelte-kit-prerelease-ts/project.json
index e38bfd206d3d..e9ec53e855c8 100644
--- a/code/sandbox/svelte-kit-prerelease-ts/project.json
+++ b/code/sandbox/svelte-kit-prerelease-ts/project.json
@@ -3,12 +3,12 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": [
- "cli",
+ "storybook",
"core",
- "essentials",
- "interactions",
- "links",
- "onboarding",
+ "addon-essentials",
+ "addon-interactions",
+ "addon-links",
+ "addon-onboarding",
"blocks",
"sveltekit"
],
diff --git a/code/sandbox/svelte-kit-skeleton-js/project.json b/code/sandbox/svelte-kit-skeleton-js/project.json
index a7bed3a416e6..c0ac8adf0ba2 100644
--- a/code/sandbox/svelte-kit-skeleton-js/project.json
+++ b/code/sandbox/svelte-kit-skeleton-js/project.json
@@ -3,12 +3,12 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": [
- "cli",
+ "storybook",
"core",
- "essentials",
- "interactions",
- "links",
- "onboarding",
+ "addon-essentials",
+ "addon-interactions",
+ "addon-links",
+ "addon-onboarding",
"blocks",
"sveltekit"
],
diff --git a/code/sandbox/svelte-kit-skeleton-ts/project.json b/code/sandbox/svelte-kit-skeleton-ts/project.json
index 55f7fd0e2256..17f7e5cdee4e 100644
--- a/code/sandbox/svelte-kit-skeleton-ts/project.json
+++ b/code/sandbox/svelte-kit-skeleton-ts/project.json
@@ -3,12 +3,12 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": [
- "cli",
+ "storybook",
"core",
- "essentials",
- "interactions",
- "links",
- "onboarding",
+ "addon-essentials",
+ "addon-interactions",
+ "addon-links",
+ "addon-onboarding",
"blocks",
"sveltekit"
],
diff --git a/code/sandbox/svelte-vite-default-js/project.json b/code/sandbox/svelte-vite-default-js/project.json
index 096864499ea4..d93d4e9b6ab1 100644
--- a/code/sandbox/svelte-vite-default-js/project.json
+++ b/code/sandbox/svelte-vite-default-js/project.json
@@ -3,12 +3,12 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": [
- "cli",
+ "storybook",
"core",
- "essentials",
- "interactions",
- "links",
- "onboarding",
+ "addon-essentials",
+ "addon-interactions",
+ "addon-links",
+ "addon-onboarding",
"blocks",
"svelte-vite"
],
diff --git a/code/sandbox/svelte-vite-default-ts/project.json b/code/sandbox/svelte-vite-default-ts/project.json
index 8236af79dcdc..90dadf8177f4 100644
--- a/code/sandbox/svelte-vite-default-ts/project.json
+++ b/code/sandbox/svelte-vite-default-ts/project.json
@@ -3,12 +3,12 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": [
- "cli",
+ "storybook",
"core",
- "essentials",
- "interactions",
- "links",
- "onboarding",
+ "addon-essentials",
+ "addon-interactions",
+ "addon-links",
+ "addon-onboarding",
"blocks",
"svelte-vite"
],
diff --git a/code/sandbox/vue-cli-default-js/project.json b/code/sandbox/vue-cli-default-js/project.json
index dfbbc9051756..fa29b401d74a 100644
--- a/code/sandbox/vue-cli-default-js/project.json
+++ b/code/sandbox/vue-cli-default-js/project.json
@@ -3,12 +3,12 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": [
- "cli",
+ "storybook",
"core",
- "essentials",
- "interactions",
- "links",
- "onboarding",
+ "addon-essentials",
+ "addon-interactions",
+ "addon-links",
+ "addon-onboarding",
"blocks",
"vue3-webpack5"
],
diff --git a/code/sandbox/vue3-vite-default-js/project.json b/code/sandbox/vue3-vite-default-js/project.json
index 8c49705a9ee0..6bbb297d51cd 100644
--- a/code/sandbox/vue3-vite-default-js/project.json
+++ b/code/sandbox/vue3-vite-default-js/project.json
@@ -3,12 +3,12 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": [
- "cli",
+ "storybook",
"core",
- "essentials",
- "interactions",
- "links",
- "onboarding",
+ "addon-essentials",
+ "addon-interactions",
+ "addon-links",
+ "addon-onboarding",
"blocks",
"vue3-vite"
],
diff --git a/code/sandbox/vue3-vite-default-ts/project.json b/code/sandbox/vue3-vite-default-ts/project.json
index 223d11d694c0..ad777a4b5ece 100644
--- a/code/sandbox/vue3-vite-default-ts/project.json
+++ b/code/sandbox/vue3-vite-default-ts/project.json
@@ -3,12 +3,12 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"implicitDependencies": [
- "cli",
+ "storybook",
"core",
- "essentials",
- "interactions",
- "links",
- "onboarding",
+ "addon-essentials",
+ "addon-interactions",
+ "addon-links",
+ "addon-onboarding",
"blocks",
"vue3-vite"
],
diff --git a/scripts/prepare/addon-bundle.ts b/scripts/prepare/addon-bundle.ts
index 14c62791514e..fa5e14a0e4c4 100755
--- a/scripts/prepare/addon-bundle.ts
+++ b/scripts/prepare/addon-bundle.ts
@@ -1,5 +1,7 @@
+import { writeFile } from 'node:fs/promises';
import { builtinModules } from 'node:module';
+import type { Metafile } from 'esbuild';
import aliasPlugin from 'esbuild-plugin-alias';
import * as fs from 'fs-extra';
import { glob } from 'glob';
@@ -13,6 +15,7 @@ import type { PackageJson } from 'type-fest';
import { globalPackages as globalManagerPackages } from '../../code/core/src/manager/globals/globals';
import { globalPackages as globalPreviewPackages } from '../../code/core/src/preview/globals/globals';
import { exec } from '../utils/exec';
+import { esbuild } from './tools';
/* TYPES */
@@ -34,6 +37,8 @@ type DtsConfigSection = Pick;
/* MAIN */
+const OUT_DIR = join(process.cwd(), 'dist');
+
export const nodeInternals = [
'module',
'node:module',
@@ -61,19 +66,30 @@ const run = async ({ cwd, flags }: { cwd: string; flags: string[] }) => {
await exec(`jiti ${pre}`, { cwd });
}
+ const metafilesDir = join(
+ __dirname,
+ '..',
+ '..',
+ 'code',
+ 'bench',
+ 'esbuild-metafiles',
+ name.replace('@storybook/', '')
+ );
+
const reset = hasFlag(flags, 'reset');
const watch = hasFlag(flags, 'watch');
const optimized = hasFlag(flags, 'optimized');
if (reset) {
- await fs.emptyDir(join(process.cwd(), 'dist'));
+ await fs.emptyDir(OUT_DIR);
+ await fs.emptyDir(metafilesDir);
}
- const tasks: Promise[] = [];
+ const tasks: (() => Promise)[] = [];
- const outDir = join(process.cwd(), 'dist');
const commonOptions: Options = {
- outDir,
+ outDir: OUT_DIR,
+ metafile: true,
silent: true,
treeshake: true,
shims: false,
@@ -117,37 +133,42 @@ const run = async ({ cwd, flags }: { cwd: string; flags: string[] }) => {
optimized,
});
- tasks.push(
- build({
- ...commonOptions,
- ...(optimized ? dtsConfig : {}),
- ...browserOptions,
- entry: exportEntries,
- external: [...commonExternals, ...globalManagerPackages, ...globalPreviewPackages],
- }),
- build({
- ...commonOptions,
- ...(optimized ? dtsConfig : {}),
- entry: exportEntries,
- format: ['cjs'],
- target: browserOptions.target,
- platform: 'neutral',
- external: [...commonExternals, ...globalManagerPackages, ...globalPreviewPackages],
- esbuildOptions: (options) => {
- options.platform = 'neutral';
- Object.assign(options, getESBuildOptions(optimized));
- },
- })
- );
+ tasks.push(async () => {
+ await Promise.all([
+ build({
+ ...commonOptions,
+ ...(optimized ? dtsConfig : {}),
+ ...browserOptions,
+ entry: exportEntries,
+ external: [...commonExternals, ...globalManagerPackages, ...globalPreviewPackages],
+ }),
+ build({
+ ...commonOptions,
+ ...(optimized ? dtsConfig : {}),
+ entry: exportEntries,
+ format: ['cjs'],
+ target: browserOptions.target,
+ platform: 'neutral',
+ external: [...commonExternals, ...globalManagerPackages, ...globalPreviewPackages],
+ esbuildOptions: (options) => {
+ options.platform = 'neutral';
+ Object.assign(options, getESBuildOptions(optimized));
+ },
+ }),
+ ]);
+ if (!watch) {
+ await readMetafiles({ formats: ['esm', 'cjs'] });
+ }
+ });
if (tsConfigExists && !optimized) {
- tasks.push(...exportEntries.map(generateDTSMapperFile));
+ tasks.push(...exportEntries.map((entry) => () => generateDTSMapperFile(entry)));
}
}
if (managerEntries.length > 0) {
- tasks.push(
- build({
+ tasks.push(async () => {
+ await build({
...commonOptions,
...browserOptions,
entry: managerEntries.map((e: string) => slash(join(cwd, e))),
@@ -155,8 +176,11 @@ const run = async ({ cwd, flags }: { cwd: string; flags: string[] }) => {
js: '.js',
}),
external: [...commonExternals, ...globalManagerPackages],
- })
- );
+ });
+ if (!watch) {
+ await readMetafiles({ formats: ['esm'] });
+ }
+ });
}
if (previewEntries.length > 0) {
@@ -165,19 +189,22 @@ const run = async ({ cwd, flags }: { cwd: string; flags: string[] }) => {
entries: previewEntries,
optimized,
});
- tasks.push(
- build({
+ tasks.push(async () => {
+ await build({
...commonOptions,
...(optimized ? dtsConfig : {}),
...browserOptions,
format: ['esm', 'cjs'],
entry: previewEntries.map((e: string) => slash(join(cwd, e))),
external: [...commonExternals, ...globalPreviewPackages],
- })
- );
+ });
+ if (!watch) {
+ await readMetafiles({ formats: ['esm', 'cjs'] });
+ }
+ });
if (tsConfigExists && !optimized) {
- tasks.push(...previewEntries.map(generateDTSMapperFile));
+ tasks.push(...previewEntries.map((entry) => () => generateDTSMapperFile(entry)));
}
}
@@ -187,56 +214,60 @@ const run = async ({ cwd, flags }: { cwd: string; flags: string[] }) => {
entries: nodeEntries,
optimized,
});
- tasks.push(
- build({
- ...commonOptions,
- entry: nodeEntries.map((e: string) => slash(join(cwd, e))),
- format: ['cjs'],
- target: 'node18',
- platform: 'node',
- external: commonExternals,
- esbuildOptions: (c) => {
- c.platform = 'node';
- Object.assign(c, getESBuildOptions(optimized));
- },
- })
- );
- tasks.push(
- build({
- ...commonOptions,
- ...(optimized ? dtsConfig : {}),
- entry: nodeEntries.map((e: string) => slash(join(cwd, e))),
- format: ['esm'],
- target: 'node18',
- platform: 'neutral',
- banner: {
- js: dedent`
- import ESM_COMPAT_Module from "node:module";
- import { fileURLToPath as ESM_COMPAT_fileURLToPath } from 'node:url';
- import { dirname as ESM_COMPAT_dirname } from 'node:path';
- const __filename = ESM_COMPAT_fileURLToPath(import.meta.url);
- const __dirname = ESM_COMPAT_dirname(__filename);
- const require = ESM_COMPAT_Module.createRequire(import.meta.url);
- `,
- },
- external: [...commonExternals, ...nodeInternals],
- esbuildOptions: (c) => {
- c.mainFields = ['main', 'module', 'node'];
- c.conditions = ['node', 'module', 'import', 'require'];
- c.platform = 'neutral';
- Object.assign(c, getESBuildOptions(optimized));
- },
- })
- );
+ tasks.push(async () => {
+ await Promise.all([
+ build({
+ ...commonOptions,
+ entry: nodeEntries.map((e: string) => slash(join(cwd, e))),
+ format: ['cjs'],
+ target: 'node18',
+ platform: 'node',
+ external: commonExternals,
+ esbuildOptions: (c) => {
+ c.platform = 'node';
+ Object.assign(c, getESBuildOptions(optimized));
+ },
+ }),
+ build({
+ ...commonOptions,
+ ...(optimized ? dtsConfig : {}),
+ entry: nodeEntries.map((e: string) => slash(join(cwd, e))),
+ format: ['esm'],
+ target: 'node18',
+ platform: 'neutral',
+ banner: {
+ js: dedent`
+ import ESM_COMPAT_Module from "node:module";
+ import { fileURLToPath as ESM_COMPAT_fileURLToPath } from 'node:url';
+ import { dirname as ESM_COMPAT_dirname } from 'node:path';
+ const __filename = ESM_COMPAT_fileURLToPath(import.meta.url);
+ const __dirname = ESM_COMPAT_dirname(__filename);
+ const require = ESM_COMPAT_Module.createRequire(import.meta.url);
+ `,
+ },
+ external: [...commonExternals, ...nodeInternals],
+ esbuildOptions: (c) => {
+ c.mainFields = ['main', 'module', 'node'];
+ c.conditions = ['node', 'module', 'import', 'require'];
+ c.platform = 'neutral';
+ Object.assign(c, getESBuildOptions(optimized));
+ },
+ }),
+ ]);
+ if (!watch) {
+ await readMetafiles({ formats: ['esm', 'cjs'] });
+ }
+ });
if (tsConfigExists && !optimized) {
- tasks.push(...nodeEntries.map(generateDTSMapperFile));
+ tasks.push(...nodeEntries.map((entry) => () => generateDTSMapperFile(entry)));
}
}
- await Promise.all(tasks);
-
- const dtsFiles = await glob(outDir + '/**/*.d.ts');
+ for (const task of tasks) {
+ await task();
+ }
+ const dtsFiles = await glob(OUT_DIR + '/**/*.d.ts');
await Promise.all(
dtsFiles.map(async (file) => {
const content = await fs.readFile(file, 'utf-8');
@@ -247,6 +278,10 @@ const run = async ({ cwd, flags }: { cwd: string; flags: string[] }) => {
})
);
+ if (!watch) {
+ await saveMetafiles({ metafilesDir });
+ }
+
if (post) {
await exec(`jiti ${post}`, { cwd }, { debug: true });
}
@@ -311,6 +346,34 @@ async function generateDTSMapperFile(file: string) {
);
}
+const metafile: Metafile = {
+ inputs: {},
+ outputs: {},
+};
+
+async function readMetafiles({ formats }: { formats: Formats[] }) {
+ await Promise.all(
+ formats.map(async (format) => {
+ const fromFilename = `metafile-${format}.json`;
+ const currentMetafile = await fs.readJson(join(OUT_DIR, fromFilename));
+ metafile.inputs = { ...metafile.inputs, ...currentMetafile.inputs };
+ metafile.outputs = { ...metafile.outputs, ...currentMetafile.outputs };
+
+ await fs.rm(join(OUT_DIR, fromFilename));
+ })
+ );
+}
+
+async function saveMetafiles({ metafilesDir }: { metafilesDir: string }) {
+ await fs.ensureDir(metafilesDir);
+
+ await writeFile(join(metafilesDir, 'metafile.json'), JSON.stringify(metafile, null, 2));
+ await writeFile(
+ join(metafilesDir, 'metafile.txt'),
+ await esbuild.analyzeMetafile(metafile, { color: false, verbose: false })
+ );
+}
+
const hasFlag = (flags: string[], name: string) => !!flags.find((s) => s.startsWith(`--${name}`));
/* SELF EXECUTION */
diff --git a/scripts/prepare/bundle.ts b/scripts/prepare/bundle.ts
index 81a7b301fe41..4651774257c8 100755
--- a/scripts/prepare/bundle.ts
+++ b/scripts/prepare/bundle.ts
@@ -1,5 +1,7 @@
+import { writeFile } from 'node:fs/promises';
import { dirname, join, parse, posix, relative, resolve, sep } from 'node:path';
+import type { Metafile } from 'esbuild';
import aliasPlugin from 'esbuild-plugin-alias';
import * as fs from 'fs-extra';
import { glob } from 'glob';
@@ -10,6 +12,7 @@ import { build } from 'tsup';
import type { PackageJson } from 'type-fest';
import { exec } from '../utils/exec';
+import { esbuild } from './tools';
/* TYPES */
@@ -30,6 +33,8 @@ type DtsConfigSection = Pick;
/* MAIN */
+const OUT_DIR = join(process.cwd(), 'dist');
+
const run = async ({ cwd, flags }: { cwd: string; flags: string[] }) => {
const {
name,
@@ -50,17 +55,26 @@ const run = async ({ cwd, flags }: { cwd: string; flags: string[] }) => {
await exec(`jiti ${pre}`, { cwd });
}
+ const metafilesDir = join(
+ __dirname,
+ '..',
+ '..',
+ 'code',
+ 'bench',
+ 'esbuild-metafiles',
+ name.replace('@storybook', '')
+ );
+
const reset = hasFlag(flags, 'reset');
const watch = hasFlag(flags, 'watch');
const optimized = hasFlag(flags, 'optimized');
-
if (reset) {
- await fs.emptyDir(join(process.cwd(), 'dist'));
+ await fs.emptyDir(OUT_DIR);
+ await fs.emptyDir(metafilesDir);
}
const tasks: Promise[] = [];
- const outDir = join(process.cwd(), 'dist');
const externals = [
name,
...extraExternals,
@@ -93,8 +107,9 @@ const run = async ({ cwd, flags }: { cwd: string; flags: string[] }) => {
entry: nonPresetEntries,
shims: false,
watch,
- outDir,
+ outDir: OUT_DIR,
sourcemap: false,
+ metafile: true,
format: ['esm'],
target: platform === 'node' ? ['node18'] : ['chrome100', 'safari15', 'firefox91'],
clean: false,
@@ -127,8 +142,9 @@ const run = async ({ cwd, flags }: { cwd: string; flags: string[] }) => {
silent: true,
entry: allEntries,
watch,
- outDir,
+ outDir: OUT_DIR,
sourcemap: false,
+ metafile: true,
format: ['cjs'],
target: 'node18',
...(dtsBuild === 'cjs' ? dtsConfig : {}),
@@ -150,7 +166,11 @@ const run = async ({ cwd, flags }: { cwd: string; flags: string[] }) => {
await Promise.all(tasks);
- const dtsFiles = await glob(outDir + '/**/*.d.ts');
+ if (!watch) {
+ await saveMetafiles({ metafilesDir, formats });
+ }
+
+ const dtsFiles = await glob(OUT_DIR + '/**/*.d.ts');
await Promise.all(
dtsFiles.map(async (file) => {
const content = await fs.readFile(file, 'utf-8');
@@ -225,6 +245,37 @@ async function generateDTSMapperFile(file: string) {
);
}
+async function saveMetafiles({
+ metafilesDir,
+ formats,
+}: {
+ metafilesDir: string;
+ formats: Formats[];
+}) {
+ await fs.ensureDir(metafilesDir);
+ const metafile: Metafile = {
+ inputs: {},
+ outputs: {},
+ };
+
+ await Promise.all(
+ formats.map(async (format) => {
+ const fromFilename = `metafile-${format}.json`;
+ const currentMetafile = await fs.readJson(join(OUT_DIR, fromFilename));
+ metafile.inputs = { ...metafile.inputs, ...currentMetafile.inputs };
+ metafile.outputs = { ...metafile.outputs, ...currentMetafile.outputs };
+
+ await fs.rm(join(OUT_DIR, fromFilename));
+ })
+ );
+
+ await writeFile(join(metafilesDir, 'metafile.json'), JSON.stringify(metafile, null, 2));
+ await writeFile(
+ join(metafilesDir, 'metafile.txt'),
+ await esbuild.analyzeMetafile(metafile, { color: false, verbose: false })
+ );
+}
+
const hasFlag = (flags: string[], name: string) => !!flags.find((s) => s.startsWith(`--${name}`));
/* SELF EXECUTION */