Skip to content

Commit ff05f22

Browse files
committed
perf(cli): keep the env-graph barrel out of the CLI entry point
Splitting the commands off left a 559KB shared chunk still loaded on every invocation. That chunk was env-graph + the @env-spec parser + clack prompts + ansis, merged together because the entry reached the env-graph barrel through three edges: - helpers/error-checks.ts imports { EnvGraph, FileBasedDataSource } from the barrel, but the entry only ever wanted InvalidEnvError from that module. Moved that class to its own leaf module and pointed the entry at it. - lib/formatting.ts imported ConfigItem and VarlockError as values, though both are only used as parameter annotations. Made it an `import type`, so the edge is erased at compile time. - helpers/telemetry-usage-context.ts already deep-imports env-graph/lib/errors, which is a leaf (its only import is my-dash), so it costs nothing. error-checks.ts re-exports InvalidEnvError, so no other caller changes. The class is still defined exactly once in the bundle, which is what keeps the entry's `instanceof InvalidEnvError` catch working. Entry static closure: 1029KB -> 320KB.
1 parent 3e0e795 commit ff05f22

4 files changed

Lines changed: 22 additions & 10 deletions

File tree

packages/varlock/src/cli/cli-executable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { VARLOCK_BANNER_COLOR } from '../lib/ascii-art';
99
import { CliExitError } from './helpers/exit-error';
1010
import { fmt } from './helpers/pretty-format';
1111
import { trackCommand, trackInstall } from './helpers/telemetry';
12-
import { InvalidEnvError } from './helpers/error-checks';
12+
import { InvalidEnvError } from './helpers/invalid-env-error';
1313
import { isArgError, toCliExitError } from './helpers/arg-errors';
1414
import { checkBunVersion } from '../lib/check-bun-version';
1515
import { checkLocalVersionMismatch } from '../lib/check-local-version';

packages/varlock/src/cli/helpers/error-checks.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import {
55
LoadingError, ParseError, VarlockError,
66
} from '../../env-graph/lib/errors';
77
import { CliExitError } from './exit-error';
8+
import { InvalidEnvError } from './invalid-env-error';
9+
10+
export { InvalidEnvError };
811

912
function showErrorLocationDetails(err: VarlockError) {
1013
if (!err.location) return;
@@ -130,14 +133,6 @@ export function showPluginWarnings(envGraph: EnvGraph) {
130133
}
131134
}
132135

133-
export class InvalidEnvError extends Error {
134-
constructor() {
135-
super('Resolved config/env did not pass validation');
136-
}
137-
getFormattedOutput() {
138-
return `\n💥 ${ansis.red(this.message)} 💥\n`;
139-
}
140-
}
141136

142137
export function checkForConfigErrors(envGraph: EnvGraph, opts?: {
143138
showAll?: boolean;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import ansis from 'ansis';
2+
3+
/**
4+
* Thrown when resolved config fails validation.
5+
*
6+
* Kept in its own module (rather than alongside the `checkFor*` helpers in
7+
* `error-checks.ts`) so the CLI entry point can catch it without importing
8+
* those helpers, which pull in the whole env-graph barrel.
9+
*/
10+
export class InvalidEnvError extends Error {
11+
constructor() {
12+
super('Resolved config/env did not pass validation');
13+
}
14+
getFormattedOutput() {
15+
return `\n💥 ${ansis.red(this.message)} 💥\n`;
16+
}
17+
}

packages/varlock/src/lib/formatting.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import ansis, { type AnsiColors, type AnsiStyles } from 'ansis';
22
import _ from '@env-spec/utils/my-dash';
33

4-
import { ConfigItem, VarlockError } from '../env-graph';
4+
import type { ConfigItem, VarlockError } from '../env-graph';
55
import { redactString } from '../runtime/lib/redaction';
66

77
type ColorMod = AnsiStyles | AnsiColors;

0 commit comments

Comments
 (0)