Update stats process to use stream
MODIFY
bin-src/tasks/upload.ts
bin-src/tasks/upload.ts
@@ -29,6 +29,7 @@ import {
} from '../ui/tasks/upload';
import { Context, Task } from '../types';
import { exitCodes, setExitCode } from '../lib/setExitCode';
+import { readStatsFile } from '../trim-stats-file';
const GetUploadUrlsMutation = `
mutation GetUploadUrlsMutation($paths: [String!]!) {
@@ -154,7 +155,7 @@ export const traceChangedFiles = async (ctx: Context, task: Task) => {
const statsPath = join(ctx.sourceDir, ctx.fileInfo.statsPath);
const { changedFiles } = ctx.git;
try {
- const stats = await fs.readJson(statsPath);
+ const stats = await readStatsFile(statsPath);
const onlyStoryFiles = await getDependentStoryFiles(ctx, stats, statsPath, changedFiles);
if (onlyStoryFiles) {
ctx.onlyStoryFiles = onlyStoryFiles;

MODIFY
bin-src/trace.ts
bin-src/trace.ts
-import fs from 'fs-extra';
import meow from 'meow';
import { getDependentStoryFiles } from './lib/getDependentStoryFiles';
import { Context } from './types';
+import { readStatsFile } from './trim-stats-file';
/**
* Utility to trace a set of changed file paths to dependent story files using a Webpack stats file.
@@ -85,7 +85,7 @@ export async function main(argv: string[]) {
traceChanged: flags.mode || true,
},
} as any;
- const stats = await fs.readJson(flags.statsFile);
+ const stats = await readStatsFile(flags.statsFile);
const changedFiles = input.map((f) => f.replace(/^\.\//, ''));
await getDependentStoryFiles(ctx, stats, flags.statsFile, changedFiles);

MODIFY
bin-src/trim-stats-file.ts
bin-src/trim-stats-file.ts
import { parseChunked } from '@discoveryjs/json-ext';
-import { createReadStream, outputFile } from 'fs-extra';
+import { createReadStream, outputFile, existsSync } from 'fs-extra';
import { Stats } from './types';
const dedupe = <T>(arr: T[]) => Array.from(new Set(arr));
@@ -8,8 +8,12 @@ const isUserCode = ({ name, moduleName = name }: { name?: string; moduleName?: s
!moduleName.startsWith('(webpack)') &&
!moduleName.match(/(node_modules|webpack\/runtime)\//);
-export const readStatsFile = async (filePath: string): Promise<Stats> =>
- parseChunked(createReadStream(filePath));
+export const readStatsFile = async (filePath: string): Promise<Stats> => {
+ if (existsSync(filePath)) {
+ return parseChunked(createReadStream(filePath));
+ }
+ return undefined;
+};
/**
* Utility to trim down a `preview-stats.json` file to the bare minimum, so that it can be used to

Update stats process to use stream