Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions src/cli/actions/defaultAction.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import path from 'node:path';
import { loadFileConfig, mergeConfigs } from '../../config/configLoad.js';
import {
type RepomixConfigCli,
type RepomixConfigFile,
type RepomixConfigMerged,
type RepomixOutputStyle,
repomixConfigCliSchema,
import type {
RepomixConfigCli,
RepomixConfigFile,
RepomixConfigMerged,
RepomixOutputStyle,
} from '../../config/configSchema.js';
import { readFilePathsFromStdin } from '../../core/file/fileStdin.js';
import type { PackResult } from '../../core/packager.js';
import { generateDefaultSkillName } from '../../core/skill/skillUtils.js';
import { RepomixError, rethrowValidationErrorIfZodError } from '../../shared/errorHandle.js';
import { RepomixError } from '../../shared/errorHandle.js';
import { logger } from '../../shared/logger.js';
import { splitPatterns } from '../../shared/patternUtils.js';
import { initTaskRunner } from '../../shared/processConcurrency.js';
Expand All @@ -25,6 +24,13 @@ import type {
PingTask,
} from './workers/defaultActionWorker.js';

// Pre-warm Zod schema loading as soon as defaultAction module is imported.
// configSchema.js transitively loads Zod (~50ms). By starting the import here,
// the module loads in the background during migration check (~5ms) and other
// setup work. When loadFileConfig or buildCliConfig later calls
// import('../../config/configSchema.js'), the module is already cached.
const _configSchemaWarmup = import('../../config/configSchema.js').catch(() => {});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While pre-warming the schema is a good performance optimization, silently swallowing errors with an empty .catch(() => {}) can hide underlying issues (e.g., syntax errors, incorrect paths) and make debugging more difficult. It's better to log the error, for instance at a debug level, to maintain observability without crashing the application on a failed optimization.

Suggested change
const _configSchemaWarmup = import('../../config/configSchema.js').catch(() => {});
const _configSchemaWarmup = import('../../config/configSchema.js').catch((err) => logger.debug('Config schema pre-warming failed:', err));


export interface DefaultActionRunnerResult {
packResult: PackResult;
config: RepomixConfigMerged;
Expand Down Expand Up @@ -339,12 +345,11 @@ export const buildCliConfig = (options: CliOptions): RepomixConfigCli => {
cliConfig.skillGenerate = options.skillGenerate;
}

try {
return repomixConfigCliSchema.parse(cliConfig);
} catch (error) {
rethrowValidationErrorIfZodError(error, 'Invalid cli arguments');
throw error;
}
// CLI config is built entirely from Commander-parsed options above — each field
// is set from a typed CLI option with known values. Zod validation is redundant
// here and would require awaiting the ~50ms configSchema.js import. File configs
// (user-authored JSON) are still Zod-validated in loadFileConfig.
return cliConfig as RepomixConfigCli;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The cliConfig variable is declared with the type RepomixConfigCli on line 161. Therefore, the type assertion as RepomixConfigCli in the return statement is redundant and can be safely removed for cleaner code.

Suggested change
return cliConfig as RepomixConfigCli;
return cliConfig;

};

/**
Expand Down
5 changes: 3 additions & 2 deletions src/cli/cliRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,9 @@ export const runCli = async (directories: string[], cwd: string, options: CliOpt
return;
}

// Skip version header in stdin mode to avoid interfering with piped output from interactive tools like fzf
if (!options.stdin) {
// Skip version header in stdin/stdout/quiet mode to avoid unnecessary I/O
// (package.json read) when output would be suppressed anyway.
if (!options.stdin && !options.stdout && !options.quiet) {
const version = await getVersion();
logger.log(pc.dim(`\n📦 Repomix v${version}\n`));
}
Expand Down
Loading