-
Notifications
You must be signed in to change notification settings - Fork 182
Expand file tree
/
Copy pathbin.ts
More file actions
54 lines (50 loc) · 1.77 KB
/
bin.ts
File metadata and controls
54 lines (50 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* Entry point for the vite-plus CLI.
*
* This file initializes the CLI by passing JavaScript tool resolver functions
* to the Rust core through NAPI bindings. Each resolver function is responsible
* for locating the binary path of its respective tool using Node.js module resolution.
*
* The Rust core will call these functions when it needs to execute the corresponding
* tools (e.g., when running `vite-plus build`, it calls the vite resolver).
*/
import { run } from '../binding/index.js';
import { doc } from './resolve-doc.js';
import { fmt } from './resolve-fmt.js';
import { lib } from './resolve-lib.js';
import { lint } from './resolve-lint.js';
import { test } from './resolve-test.js';
import { vite } from './resolve-vite.js';
async function resolveUniversalViteConfig(err: null | Error, viteConfigCwd: string) {
if (err) {
throw err;
}
try {
const { resolveConfig } = await import('./config.js');
const config = await resolveConfig({ root: viteConfigCwd }, 'build');
return Promise.resolve(JSON.stringify({
lint: config.lint,
fmt: config.fmt,
}));
} catch (err) {
console.error('[vite+] resolve universal vite config error:', err);
throw err;
}
}
// Initialize the CLI with tool resolvers
// These functions will be called from Rust when needed
run({
lint, // Resolves oxlint binary for linting
lib, // Resolves tsdown binary for lib bundling
fmt, // Resolves oxfmt binary for formatting
vite, // Resolves vite binary for build/dev commands
test, // Resolves vitest binary for test commands
doc, // Resolves vitepress binary for doc commands
resolveUniversalViteConfig,
}).then((exitCode) => {
process.exit(exitCode);
})
.catch((err) => {
console.error('[vite+] run error:', err);
process.exit(1);
});