-
Notifications
You must be signed in to change notification settings - Fork 176
Expand file tree
/
Copy pathresolve-vite.ts
More file actions
47 lines (43 loc) · 1.48 KB
/
resolve-vite.ts
File metadata and controls
47 lines (43 loc) · 1.48 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
/**
* Vite tool resolver for the vite-plus CLI.
*
* This module exports a function that resolves the Vite binary path
* using Node.js module resolution. The resolved path is passed back
* to the Rust core, which then executes Vite with the appropriate
* command and arguments.
*
* Used for: `vite-plus build` and potentially `vite-plus dev` commands
*/
import { dirname, join } from 'node:path';
import { DEFAULT_ENVS, resolve } from './utils/constants.js';
/**
* Resolves the Vite binary path and environment variables.
*
* @returns Promise containing:
* - binPath: Absolute path to the Vite CLI entry point (vite.js)
* - envs: Environment variables to set when executing Vite
*
* The function first tries to resolve vite package, then falls back
* to vite package (for direct vite installations).
* It constructs the path to the CLI binary within the resolved package.
*/
export async function vite(): Promise<{
binPath: string;
envs: Record<string, string>;
}> {
// Vite's CLI binary is located at bin/vite.js relative to the package root
const vitePackagePath = dirname(resolve('@voidzero-dev/vite-plus-core'));
const binPath = join(vitePackagePath, 'cli.js');
return {
binPath,
// Pass through source map debugging environment variable if set
envs: process.env.DEBUG_DISABLE_SOURCE_MAP
? {
...DEFAULT_ENVS,
DEBUG_DISABLE_SOURCE_MAP: process.env.DEBUG_DISABLE_SOURCE_MAP,
}
: {
...DEFAULT_ENVS,
},
};
}