Skip to content

Commit

Permalink
Merge pull request #15889 from storybookjs/streaming-webpack-stats
Browse files Browse the repository at this point in the history
Write JSON stats file in streaming fashion and omit `chunks` for brevity
  • Loading branch information
ghengeveld authored and shilman committed Sep 3, 2021
1 parent 8bcc9e6 commit 8e14b1c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/core-server/package.json
Expand Up @@ -40,6 +40,7 @@
"prepare": "node ../../scripts/prepare.js"
},
"dependencies": {
"@discoveryjs/json-ext": "^0.5.3",
"@storybook/builder-webpack4": "6.3.7",
"@storybook/core-client": "6.3.7",
"@storybook/core-common": "6.3.7",
Expand Down
15 changes: 11 additions & 4 deletions lib/core-server/src/utils/output-stats.ts
@@ -1,10 +1,10 @@
import { stringifyStream } from '@discoveryjs/json-ext';
import { logger } from '@storybook/node-logger';
import chalk from 'chalk';
import fs from 'fs-extra';
import path from 'path';
import { logger } from '@storybook/node-logger';
import { Stats } from 'webpack';

import fs from 'fs-extra';

export async function outputStats(directory: string, previewStats?: any, managerStats?: any) {
if (previewStats) {
const filePath = await writeStats(directory, 'preview', previewStats as Stats);
Expand All @@ -18,6 +18,13 @@ export async function outputStats(directory: string, previewStats?: any, manager

export const writeStats = async (directory: string, name: string, stats: Stats) => {
const filePath = path.join(directory, `${name}-stats.json`);
await fs.outputFile(filePath, JSON.stringify(stats.toJson(), null, 2), 'utf8');
const { chunks, ...data } = stats.toJson(); // omit chunks, which is about half of the total data
await new Promise((resolve, reject) => {
stringifyStream(data, null, 2)
.on('error', reject)
.pipe(fs.createWriteStream(filePath))
.on('error', reject)
.on('finish', resolve);
});
return filePath;
};
1 change: 1 addition & 0 deletions lib/core-server/typings.d.ts
Expand Up @@ -7,6 +7,7 @@ declare module '@storybook/theming/paths';
declare module '@storybook/ui/paths';
declare module 'better-opn';
declare module '@storybook/ui';
declare module '@discoveryjs/json-ext';

declare module 'file-system-cache' {
export interface Options {
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Expand Up @@ -2876,6 +2876,13 @@ __metadata:
languageName: node
linkType: hard

"@discoveryjs/json-ext@npm:^0.5.3":
version: 0.5.3
resolution: "@discoveryjs/json-ext@npm:0.5.3"
checksum: 73789df18a61dfd91d839b95c403af9ba32b897c5b419d9a724de588099ce6cefc379ada7617a77dad967b6a026927faa65f55154205cfe88da8c0fca3da2986
languageName: node
linkType: hard

"@dsherret/to-absolute-glob@npm:^2.0.2":
version: 2.0.2
resolution: "@dsherret/to-absolute-glob@npm:2.0.2"
Expand Down Expand Up @@ -6672,6 +6679,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@storybook/core-server@workspace:lib/core-server"
dependencies:
"@discoveryjs/json-ext": ^0.5.3
"@storybook/builder-webpack4": 6.3.7
"@storybook/builder-webpack5": 6.3.7
"@storybook/core-client": 6.3.7
Expand Down

0 comments on commit 8e14b1c

Please sign in to comment.