Skip to content

Commit

Permalink
Add nicer formatting to TS bail reasons.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmhobbs committed Oct 17, 2024
1 parent 3953912 commit b86d797
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 26 deletions.
50 changes: 26 additions & 24 deletions node-src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,30 +332,7 @@ export interface Context {
sentinelUrls?: string[];
uploadedBytes?: number;
uploadedFiles?: number;
turboSnap?: Partial<{
unavailable?: boolean;
rootPath: string;
baseDir: string;
storybookDir: string;
staticDirs: string[];
globs: string[];
modules: string[];
tracedFiles: string[];
tracedPaths: Set<string>;
changedDependencyNames: Set<string>;
changedManifestFiles: Set<string>;
affectedModuleIds: Set<string | number>;
bailReason: {
changedPackageFiles?: string[];
changedStorybookFiles?: string[];
changedStaticFiles?: string[];
changedExternalFiles?: string[];
invalidChangedFiles?: true;
missingStatsFile?: true;
noAncestorBuild?: true;
rebuild?: true;
};
}>;
turboSnap?: TurboSnap;
mergeBase?: string;
onlyStoryFiles?: string[];
untracedFiles?: string[];
Expand Down Expand Up @@ -396,4 +373,29 @@ export interface TargetInfo {
formFields: Record<string, string>;
}

export interface TurboSnap {
unavailable?: boolean;
rootPath?: string;
baseDir?: string;
storybookDir?: string;
staticDirs?: string[];
globs?: string[];
modules?: string[];
tracedFiles?: string[];
tracedPaths?: Set<string>;
changedDependencyNames?: Set<string>;
changedManifestFiles?: Set<string>;
affectedModuleIds?: Set<string | number>;
bailReason?: {
changedPackageFiles?: string[];
changedStorybookFiles?: string[];
changedStaticFiles?: string[];
changedExternalFiles?: string[];
invalidChangedFiles?: true;
missingStatsFile?: true;
noAncestorBuild?: true;
rebuild?: true;
};
}

export { type Configuration } from './lib/getConfiguration';
40 changes: 38 additions & 2 deletions node-src/ui/messages/info/tracedAffectedFiles.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import chalk from 'chalk';
import pluralize from 'pluralize';

import { Context, Module } from '../../../types';
import { Context, Module, TurboSnap } from '../../../types';
import { info } from '../../components/icons';

const printFilePath = (filepath: string, basedir: string, expanded: boolean) => {
Expand Down Expand Up @@ -54,7 +54,9 @@ export default (
let directoryDebug;

if (expanded) {
const bailReason = ctx.turboSnap?.bailReason ? `${ctx.turboSnap.bailReason}\n\n` : '';
const bailReason = ctx.turboSnap?.bailReason
? `${formatBailReason(ctx.turboSnap.bailReason)}\n\n`
: '';
const rootPath = `${chalk.magenta(rootDirectoryNote)} ${ctx.turboSnap?.rootPath}\n\n`;
const basePath = `${chalk.magenta(baseDirectoryNote)} ${basedir}\n\n`;
const storybookPath = `${chalk.magenta(storybookDirectoryNote)} ${storybookConfigDirectory}\n\n`;
Expand Down Expand Up @@ -128,3 +130,37 @@ export default (
const note = chalk`\n\nSet {bold ${flag}} to {bold 'expanded'} to reveal underlying modules.`;
return `${summary}:\n\n${traces.join('\n\n')}${expanded ? '' : note}`;
};

const formatBailReasonSection = (name: string, files: string[]) => {
return chalk`{bold ${name}}\n` + files.map((f) => ` - ${f}`).join('\n');
};

function formatBailReason(bailReason: TurboSnap['bailReason']) {
if (!bailReason) {
return '';
}

const sections: string[] = [];

if (bailReason.changedPackageFiles) {
sections.push(formatBailReasonSection('Changed Package Files', bailReason.changedPackageFiles));
}

if (bailReason.changedStorybookFiles) {
sections.push(
formatBailReasonSection('Changed Storybook Files', bailReason.changedStorybookFiles)
);
}

if (bailReason.changedExternalFiles) {
sections.push(
formatBailReasonSection('Changed External Files', bailReason.changedExternalFiles)
);
}

if (bailReason.changedStaticFiles) {
sections.push(formatBailReasonSection('Changed Static Files', bailReason.changedStaticFiles));
}

return sections.join('\n');
}

0 comments on commit b86d797

Please sign in to comment.