Skip to content

Commit 197399a

Browse files
authored
chore: Add tsgo, run vite fmt. (#454)
This PR: * Adds a `fmt` command, and runs it on CI so we no longer check in unformatted files. * Formats a few files that weren't formatted properly before. * Adds tsgo which is faster at telling us we have 143 errors. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Adds automated formatting and typecheck tooling and wires them into CI. > > - New `fmt` script (`vite fmt`) with config in `vite.config.ts` (ignore patterns, package.json/import sorting); printed in CI help and enforced in CI (`vite fmt --check`, `pnpm fmt` in upgrade workflow) > - package.json: switch `typecheck` to `tsgo`, add `tsgo` script; add `@typescript/native-preview` to dev deps > - Workflows: run formatter checks in CLI E2E; upgrade-deps now formats code after syncing and dedupe > - pnpm workspace/catalog/lockfile updated to include TypeScript native preview artifacts > - Minor code formatting/ordering cleanups across CLI/global files (no functional changes) > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 56bf307. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 9162e54 commit 197399a

12 files changed

Lines changed: 184 additions & 142 deletions

File tree

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ jobs:
194194
vite --version
195195
vite -h
196196
197+
- name: Run CLI fmt
198+
if: ${{ matrix.os != 'windows-latest' }}
199+
run: vite fmt --check
200+
197201
- name: Run CLI lint
198202
run: vite run lint
199203

.github/workflows/upgrade-deps.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ jobs:
5757
run: |
5858
pnpm install --no-frozen-lockfile
5959
pnpm dedupe
60+
61+
- name: Format code
62+
run: pnpm fmt
6063

6164
- name: Close and delete previous PR
6265
env:

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
"bootstrap-cli": "pnpm build && pnpm install-global-cli",
1313
"bootstrap-cli:ci": "pnpm install-global-cli",
1414
"install-global-cli": "pnpm --filter=vite-plus-cli copy-binding && npm install -g ./packages/global --force",
15-
"typecheck": "tsc -b tsconfig.json",
15+
"typecheck": "tsgo -b tsconfig.json",
16+
"tsgo": "tsgo -b tsconfig.json",
1617
"lint": "vite lint --type-aware --threads 4",
1718
"test": "vite test run && pnpm -r snap-test",
19+
"fmt": "vite fmt",
1820
"test:unit": "vite test run",
1921
"docs:dev": "pnpm --filter=./docs dev",
2022
"docs:build": "pnpm --filter=./docs build",
@@ -24,7 +26,7 @@
2426
"@oxc-node/cli": "catalog:",
2527
"@oxc-node/core": "catalog:",
2628
"@types/node": "catalog:",
27-
"vite-plus": "workspace:*",
29+
"@typescript/native-preview": "catalog:",
2830
"@voidzero-dev/vite-plus-tools": "workspace:*",
2931
"husky": "catalog:",
3032
"lint-staged": "catalog:",
@@ -33,6 +35,7 @@
3335
"playwright": "catalog:",
3436
"typescript": "catalog:",
3537
"vite": "catalog:",
38+
"vite-plus": "workspace:*",
3639
"vitest": "catalog:"
3740
},
3841
"lint-staged": {

packages/cli/build.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ const CORE_PACKAGE_NAME = '@voidzero-dev/vite-plus-core';
3838
const skipNative = process.argv.includes('--skip-native');
3939
const skipTs = process.argv.includes('--skip-ts');
4040
// Filter out custom flags before passing to NAPI CLI
41-
const napiArgs = process.argv.slice(2).filter((arg) => arg !== '--skip-native' && arg !== '--skip-ts');
41+
const napiArgs = process.argv
42+
.slice(2)
43+
.filter((arg) => arg !== '--skip-native' && arg !== '--skip-ts');
4244

4345
// Build native first - TypeScript may depend on the generated binding types
4446
if (!skipNative) {

packages/global/src/migration/bin.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ import {
1717
selectAgentTargetPath,
1818
writeAgentInstructions,
1919
} from '../utils/index.js';
20+
import { getVitePlusHeader } from '../utils/terminal.js';
2021
import {
2122
checkVitestVersion,
2223
checkViteVersion,
2324
rewriteMonorepo,
2425
rewriteStandaloneProject,
2526
} from './migrator.js';
26-
import { getVitePlusHeader } from '../utils/terminal.js';
2727

2828
const { green, gray } = colors;
2929

@@ -103,8 +103,7 @@ async function main() {
103103

104104
const workspaceInfoOptional = await detectWorkspace(projectPath);
105105
const packageManager =
106-
workspaceInfoOptional.packageManager ??
107-
(await selectPackageManager(options.interactive));
106+
workspaceInfoOptional.packageManager ?? (await selectPackageManager(options.interactive));
108107

109108
// ensure the package manager is installed by vite-plus
110109
const downloadResult = await downloadPackageManager(

packages/global/src/new/bin.ts

Lines changed: 24 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,17 @@ import {
2222
detectExistingAgentTargetPath,
2323
writeAgentInstructions,
2424
} from '../utils/index.js';
25+
import { getVitePlusHeader } from '../utils/terminal.js';
2526
import type { ExecutionResult } from './command.js';
2627
import { discoverTemplate, inferParentDir } from './discovery.js';
27-
import {
28-
cancelAndExit,
29-
checkProjectDirExists,
30-
promptPackageNameAndTargetDir,
31-
} from './prompts.js';
28+
import { cancelAndExit, checkProjectDirExists, promptPackageNameAndTargetDir } from './prompts.js';
3229
import {
3330
executeBuiltinTemplate,
3431
executeMonorepoTemplate,
3532
executeRemoteTemplate,
3633
} from './templates/index.js';
3734
import { BuiltinTemplate, TemplateType } from './templates/types.js';
3835
import { formatTargetDir } from './utils.js';
39-
import { getVitePlusHeader } from '../utils/terminal.js';
4036

4137
const { blue, cyan, green, gray } = colors;
4238

@@ -115,8 +111,7 @@ function parseArgs() {
115111
const viteArgs = separatorIndex >= 0 ? args.slice(0, separatorIndex) : args;
116112

117113
// Arguments after -- are template options
118-
const templateArgs =
119-
separatorIndex >= 0 ? args.slice(separatorIndex + 1) : [];
114+
const templateArgs = separatorIndex >= 0 ? args.slice(separatorIndex + 1) : [];
120115

121116
const parsed = mri<{
122117
directory?: string;
@@ -171,9 +166,7 @@ Template name is required when running in non-interactive mode
171166
Usage: vite new [TEMPLATE] [OPTIONS] [-- TEMPLATE_OPTIONS]
172167
173168
Example:
174-
${gray(
175-
'# Create a new application in non-interactive mode with a custom target directory',
176-
)}
169+
${gray('# Create a new application in non-interactive mode with a custom target directory')}
177170
vite new vite:application --no-interactive --directory=apps/my-app
178171
179172
Use \`vite new --list\` to list all available templates, or run \`vite new --help\` for more information.
@@ -292,10 +285,7 @@ Use \`vite new --list\` to list all available templates, or run \`vite new --hel
292285

293286
const isBuiltinTemplate = selectedTemplateName.startsWith('vite:');
294287
if (targetDir && !isBuiltinTemplate) {
295-
cancelAndExit(
296-
'The --directory option is only available for builtin templates',
297-
1,
298-
);
288+
cancelAndExit('The --directory option is only available for builtin templates', 1);
299289
}
300290
if (selectedTemplateName === BuiltinTemplate.monorepo && isMonorepo) {
301291
prompts.log.info(
@@ -371,16 +361,11 @@ Use \`vite new --list\` to list all available templates, or run \`vite new --hel
371361
packageName = selected.packageName;
372362
targetDir = selected.targetDir;
373363
} else {
374-
let defaultPackageName = `vite-plus-${
375-
selectedTemplateName.split(':')[1]
376-
}`;
364+
let defaultPackageName = `vite-plus-${selectedTemplateName.split(':')[1]}`;
377365
if (workspaceInfoOptional.monorepoScope) {
378366
defaultPackageName = `${workspaceInfoOptional.monorepoScope}/${defaultPackageName}`;
379367
}
380-
const selected = await promptPackageNameAndTargetDir(
381-
defaultPackageName,
382-
options.interactive,
383-
);
368+
const selected = await promptPackageNameAndTargetDir(defaultPackageName, options.interactive);
384369
packageName = selected.packageName;
385370
targetDir = selectedParentDir
386371
? path.join(selectedParentDir, selected.targetDir)
@@ -390,8 +375,7 @@ Use \`vite new --list\` to list all available templates, or run \`vite new --hel
390375

391376
// Prompt for package manager or use default
392377
const packageManager =
393-
workspaceInfoOptional.packageManager ??
394-
(await selectPackageManager(options.interactive));
378+
workspaceInfoOptional.packageManager ?? (await selectPackageManager(options.interactive));
395379
// ensure the package manager is installed by vite-plus
396380
const downloadResult = await downloadPackageManager(
397381
packageManager,
@@ -439,20 +423,14 @@ Use \`vite new --list\` to list all available templates, or run \`vite new --hel
439423
// #region Handle monorepo template
440424
if (templateInfo.command === BuiltinTemplate.monorepo) {
441425
prompts.log.info(`Target directory: ${cyan(targetDir)}`);
442-
await checkProjectDirExists(
443-
path.join(workspaceInfo.rootDir, targetDir),
444-
options.interactive,
445-
);
426+
await checkProjectDirExists(path.join(workspaceInfo.rootDir, targetDir), options.interactive);
446427
const result = await executeMonorepoTemplate(
447428
workspaceInfo,
448429
{ ...templateInfo, packageName, targetDir },
449430
options.interactive,
450431
);
451432
if (result.exitCode !== 0) {
452-
cancelAndExit(
453-
`Failed to create monorepo, exit code: ${result.exitCode}`,
454-
result.exitCode,
455-
);
433+
cancelAndExit(`Failed to create monorepo, exit code: ${result.exitCode}`, result.exitCode);
456434
}
457435

458436
// rewrite monorepo to add vite-plus dependencies
@@ -477,16 +455,11 @@ Use \`vite new --list\` to list all available templates, or run \`vite new --hel
477455
if (templateInfo.type === TemplateType.builtin) {
478456
// prompt for package name if not provided
479457
if (!targetDir) {
480-
let defaultPackageName = `vite-plus-${
481-
templateInfo.command.split(':')[1]
482-
}`;
458+
let defaultPackageName = `vite-plus-${templateInfo.command.split(':')[1]}`;
483459
if (workspaceInfo.monorepoScope) {
484460
defaultPackageName = `${workspaceInfo.monorepoScope}/${defaultPackageName}`;
485461
}
486-
const selected = await promptPackageNameAndTargetDir(
487-
defaultPackageName,
488-
options.interactive,
489-
);
462+
const selected = await promptPackageNameAndTargetDir(defaultPackageName, options.interactive);
490463
packageName = selected.packageName;
491464
targetDir = templateInfo.parentDir
492465
? path.join(templateInfo.parentDir, selected.targetDir)
@@ -617,48 +590,23 @@ function showAvailableTemplates() {
617590
console.log('');
618591

619592
console.log(blue('Vite+ Built-in Templates:'));
620-
console.log(
621-
' • vite:monorepo ' + gray('- Create a new monorepo'),
622-
);
623-
console.log(
624-
' • vite:application ' + gray('- Create a new application'),
625-
);
626-
console.log(
627-
' • vite:library ' + gray('- Create a new library'),
628-
);
629-
console.log(
630-
' • vite:generator ' +
631-
gray('- Scaffold a new code generator'),
632-
);
593+
console.log(' • vite:monorepo ' + gray('- Create a new monorepo'));
594+
console.log(' • vite:application ' + gray('- Create a new application'));
595+
console.log(' • vite:library ' + gray('- Create a new library'));
596+
console.log(' • vite:generator ' + gray('- Scaffold a new code generator'));
633597
console.log('');
634598

635599
console.log(green('Popular Remote Templates:'));
636-
console.log(
637-
' • create-vite ' + gray('- Official Vite templates'),
638-
);
639-
console.log(
640-
' • @tanstack/create-start ' + gray('- TanStack applications'),
641-
);
642-
console.log(
643-
' • create-next-app ' + gray('- Next.js application'),
644-
);
645-
console.log(
646-
' • create-nuxt ' + gray('- Nuxt application'),
647-
);
648-
console.log(
649-
' • create-typescript-app ' + gray('- TypeScript application'),
650-
);
651-
console.log(
652-
' • create-react-router ' + gray('- React Router application'),
653-
);
600+
console.log(' • create-vite ' + gray('- Official Vite templates'));
601+
console.log(' • @tanstack/create-start ' + gray('- TanStack applications'));
602+
console.log(' • create-next-app ' + gray('- Next.js application'));
603+
console.log(' • create-nuxt ' + gray('- Nuxt application'));
604+
console.log(' • create-typescript-app ' + gray('- TypeScript application'));
605+
console.log(' • create-react-router ' + gray('- React Router application'));
654606
console.log(' • create-vue ' + gray('- Vue application'));
655607

656-
console.log(
657-
'\n' + gray('Run ') + cyan('vite new') + gray(' for interactive mode'),
658-
);
659-
console.log(
660-
gray('Run ') + cyan('vite new <template>') + gray(' to use any template'),
661-
);
608+
console.log('\n' + gray('Run ') + cyan('vite new') + gray(' for interactive mode'));
609+
console.log(gray('Run ') + cyan('vite new <template>') + gray(' to use any template'));
662610
console.log(
663611
gray('Run ') +
664612
cyan('vite new <template> -- <options>') +

packages/global/src/utils/terminal.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,14 @@ const RESET = `${CSI}0m`;
99
const fgRgb = (r: number, g: number, b: number) => `${CSI}38;2;${r};${g};${b}m`;
1010

1111
const shouldColorize = (stream = process.stdout) =>
12-
stream?.isTTY &&
13-
(typeof stream.hasColors === 'function' ? stream.hasColors() : true);
12+
stream?.isTTY && (typeof stream.hasColors === 'function' ? stream.hasColors() : true);
1413

1514
function supportsTrueColor(stream = process.stdout) {
1615
if (!stream?.isTTY) {
1716
return false;
1817
}
1918

20-
const depth =
21-
typeof stream.getColorDepth === 'function' ? stream.getColorDepth() : 1;
19+
const depth = typeof stream.getColorDepth === 'function' ? stream.getColorDepth() : 1;
2220
return depth >= 24;
2321
}
2422

@@ -192,16 +190,11 @@ export async function getVitePlusHeader() {
192190

193191
if (!colors) {
194192
const fg = await getForegroundColor();
195-
colors = fg
196-
? gradient(text.length, fg, purple)
197-
: fadeToColor(text.length, purple);
193+
colors = fg ? gradient(text.length, fg, purple) : fadeToColor(text.length, purple);
198194
}
199195

200196
return `${styleText(
201197
'bold',
202-
`VITE+(${styleText(
203-
'blueBright',
204-
'⚡︎',
205-
)}) - The Unified Toolchain ${colorize(text, colors)}`,
198+
`VITE+(${styleText('blueBright', '⚡︎')}) - The Unified Toolchain ${colorize(text, colors)}`,
206199
)}`;
207200
}

packages/global/src/version.ts

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,7 @@ function readPackageVersionFromPath(packageJsonPath: string): string | null {
5252
return readPackageJsonFromPath(packageJsonPath)?.version ?? null;
5353
}
5454

55-
function resolvePackageJson(
56-
packageName: string,
57-
baseDir: string,
58-
): PackageJson | null {
55+
function resolvePackageJson(packageName: string, baseDir: string): PackageJson | null {
5956
try {
6057
const packageJsonPath = require.resolve(`${packageName}/package.json`, {
6158
paths: [baseDir],
@@ -66,13 +63,10 @@ function resolvePackageJson(
6663
}
6764
}
6865

69-
function resolveToolVersion(
70-
tool: ToolVersionSpec,
71-
localPackagePath: string,
72-
): string | null {
66+
function resolveToolVersion(tool: ToolVersionSpec, localPackagePath: string): string | null {
7367
const pkg = resolvePackageJson(tool.packageName, localPackagePath);
7468
const bundledVersion = tool.bundledVersionKey
75-
? pkg?.bundledVersions?.[tool.bundledVersionKey] ?? null
69+
? (pkg?.bundledVersions?.[tool.bundledVersionKey] ?? null)
7670
: null;
7771
if (bundledVersion) {
7872
return bundledVersion;
@@ -86,18 +80,14 @@ function resolveToolVersion(
8680
return null;
8781
}
8882

89-
function formatToolVersion(
90-
tool: ToolVersionSpec,
91-
version: string | null,
92-
): string {
83+
function formatToolVersion(tool: ToolVersionSpec, version: string | null): string {
9384
return `${tool.displayName} ${version ? `v${version}` : `Not found`}`;
9485
}
9586

9687
const cliLabel = 'vite-plus-cli';
9788
const localLabel = 'vite-plus';
9889
const columnWidth = cliLabel.length + 1;
99-
const getColumnWidth = (label: string) =>
100-
Math.max(0, columnWidth - label.length);
90+
const getColumnWidth = (label: string) => Math.max(0, columnWidth - label.length);
10191

10292
/**
10393
* Print version information for both local and global CLI
@@ -172,11 +162,7 @@ export async function printVersion(cwd: string) {
172162
tool,
173163
version: resolveToolVersion(tool, localMetadata.path),
174164
}));
175-
if (
176-
resolvedTools.some(
177-
({ tool, version }) => tool.bundledVersionKey && !version,
178-
)
179-
) {
165+
if (resolvedTools.some(({ tool, version }) => tool.bundledVersionKey && !version)) {
180166
return;
181167
}
182168

packages/test/build.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,9 @@ async function patchVitestCoreResolver() {
11921192

11931193
if (!content.includes(oldPattern)) {
11941194
throw new Error(
1195-
'Could not find VitestCoreResolver pattern to patch in ' + cliApiChunk + '. ' +
1195+
'Could not find VitestCoreResolver pattern to patch in ' +
1196+
cliApiChunk +
1197+
'. ' +
11961198
'This likely means vitest code has changed and the patch needs to be updated.',
11971199
);
11981200
}

0 commit comments

Comments
 (0)