Skip to content

Commit

Permalink
Add an error if you run --stats-json in Vite dev mode
Browse files Browse the repository at this point in the history
This reverts commit 1f993e2.
  • Loading branch information
tmeasday committed Feb 21, 2024
1 parent 5c8a166 commit 1f6f20d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions code/builders/builder-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"@storybook/channels": "workspace:*",
"@storybook/client-logger": "workspace:*",
"@storybook/core-common": "workspace:*",
"@storybook/core-events": "workspace:*",
"@storybook/csf-plugin": "workspace:*",
"@storybook/node-logger": "workspace:*",
"@storybook/preview": "workspace:*",
Expand Down
7 changes: 6 additions & 1 deletion code/builders/builder-vite/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { RequestHandler } from 'express';
import type { ViteDevServer } from 'vite';
import express from 'express';
import { dirname, join, parse } from 'path';
import { NoStatsForViteDevError } from '@storybook/core-events/server-errors';
import type { Options } from '@storybook/types';
import { transformIframeHtml } from './transform-iframe-html';
import { createViteServer } from './vite-server';
Expand Down Expand Up @@ -68,7 +69,11 @@ export const start: ViteBuilder['start'] = async ({

return {
bail,
stats: { toJson: () => null },
stats: {
toJson: () => {
throw new NoStatsForViteDevError();
},
},
totalTime: process.hrtime(startTime),
};
};
Expand Down
14 changes: 14 additions & 0 deletions code/lib/core-events/src/errors/server-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -576,3 +576,17 @@ export class UpgradeStorybookUnknownCurrentVersionError extends StorybookError {
`;
}
}

export class NoStatsForViteDevError extends StorybookError {
readonly category = Category.BUILDER_VITE;

readonly code = 1;

template() {
return dedent`
Unable to write preview stats as the Vite builder does not support stats in dev mode.
Please remove the \`--stats-json\` flag when running in dev mode.
`;
}
}
1 change: 1 addition & 0 deletions code/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5334,6 +5334,7 @@ __metadata:
"@storybook/channels": "workspace:*"
"@storybook/client-logger": "workspace:*"
"@storybook/core-common": "workspace:*"
"@storybook/core-events": "workspace:*"
"@storybook/csf-plugin": "workspace:*"
"@storybook/node-logger": "workspace:*"
"@storybook/preview": "workspace:*"
Expand Down

0 comments on commit 1f6f20d

Please sign in to comment.