Skip to content

Commit 49676cd

Browse files
authored
perf(cli): lazy-load init-only deps out of the vp startup path (#2490)
## Summary Apply lazy loading in `init-config.ts` so the JS resources used only by `vp lint --init` and `vp fmt --init` / `--migrate` (`utils/tsconfig.ts`, `utils/command.ts` and their dependencies) are loaded on demand instead of on every `vp` invocation. ## Benchmark `node dist/bin.js --help` on macOS (Apple Silicon), Node 24, measured with `hyperfine --warmup 5 --runs 30` against the `main` build and this branch's build placed side by side. | Command | Mean [ms] | Min [ms] | Max [ms] | Relative | |:---|---:|---:|---:|---:| | `before` (main) | 83.7 ± 0.9 | 82.1 | 85.3 | 1.10 ± 0.02 | | `after` (this PR) | 76.1 ± 0.9 | 74.2 | 78.0 | 1.00 | The static import closure of `dist/bin.js` drops from 13 files / 540 KB to 9 files / 92 KB, so every `vp` invocation parses about 450 KB less JavaScript. Package size is unchanged. <img width="1422" height="472" alt="image" src="https://github.com/user-attachments/assets/e71cd828-389b-46cc-96f6-94a5ee0cfa9b" />
1 parent ac7c1fe commit 49676cd

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

packages/cli/src/init-config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ import path from 'node:path';
44
import { hasConfigKey, mergeJsonConfig } from '../binding/index.js';
55
import { createDefaultVitePlusLintConfig } from './oxlint-plugin-config.ts';
66
import { fmt as resolveFmt } from './resolve-fmt.ts';
7-
import { runCommandSilently } from './utils/command.ts';
87
import { BASEURL_TSCONFIG_WARNING, VITE_CONFIG_FILES, VITE_PLUS_NAME } from './utils/constants.ts';
98
import { warnMsg } from './utils/terminal.ts';
10-
import { fixBaseUrlInTsconfig, hasBaseUrlInTsconfig } from './utils/tsconfig.ts';
119

1210
interface InitCommandSpec {
1311
configKey: 'lint' | 'fmt';
@@ -130,6 +128,7 @@ export default defineConfig({});
130128
}
131129

132130
async function vpFmt(cwd: string, filePath: string): Promise<void> {
131+
const { runCommandSilently } = await import('./utils/command.ts');
133132
const { binPath, envs } = await resolveFmt();
134133
const result = await runCommandSilently({
135134
command: binPath,
@@ -223,6 +222,7 @@ export async function applyToolInitConfigToViteConfig(
223222

224223
if (spec.configKey === 'lint' && hasTriggerFlag(args, ['--init'])) {
225224
const lintInitConfigPath = path.join(projectPath, '.vite-plus-lint-init.oxlintrc.json');
225+
const { fixBaseUrlInTsconfig, hasBaseUrlInTsconfig } = await import('./utils/tsconfig.ts');
226226
await fixBaseUrlInTsconfig(projectPath);
227227
// Skip typeAware/typeCheck when tsconfig still has baseUrl (unsupported by tsgolint)
228228
const hasBaseUrl = hasBaseUrlInTsconfig(projectPath);

0 commit comments

Comments
 (0)