Skip to content

Commit 8a4b371

Browse files
committed
build: split vite plus core and test
1 parent af0dc20 commit 8a4b371

64 files changed

Lines changed: 2865 additions & 2450 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/actions/build-upstream/action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ runs:
2121
fi
2222
pnpm --filter rolldown build-node
2323
pnpm --filter rolldown-vite build-types
24+
pnpm --filter=@voidzero-dev/vite-plus-core build
25+
pnpm --filter=@voidzero-dev/vite-plus-test build
2426
CC=clang pnpm --filter=@voidzero-dev/vite-plus build --target ${{ inputs.target }} --use-napi-cross
2527
env:
2628
TARGET_CC: clang
@@ -35,6 +37,8 @@ runs:
3537
fi
3638
pnpm --filter rolldown build-node
3739
pnpm --filter rolldown-vite build-types
40+
pnpm --filter=@voidzero-dev/vite-plus-core build
41+
pnpm --filter=@voidzero-dev/vite-plus-test build
3842
TARGET_CFLAGS="-D_BSD_SOURCE" pnpm --filter=@voidzero-dev/vite-plus build --target ${{ inputs.target }} --use-napi-cross
3943
env:
4044
TARGET_CC: clang
@@ -49,4 +53,6 @@ runs:
4953
fi
5054
pnpm --filter rolldown build-node
5155
pnpm --filter rolldown-vite build-types
56+
pnpm --filter=@voidzero-dev/vite-plus-core build
57+
pnpm --filter=@voidzero-dev/vite-plus-test build
5258
pnpm --filter=@voidzero-dev/vite-plus build --target ${{ inputs.target }}

.oxfmtrc.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"$schema": "./node_modules/oxfmt/configuration_schema.json",
3+
"ignorePatterns": [
4+
"packages/cli/binding/index.d.ts",
5+
"packages/cli/binding/index.js"
6+
],
7+
"singleQuote": true
8+
}

bench/generate-monorepo.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ class MonorepoGenerator {
147147
const hasVitePlusConfig = Math.random() > 0.3;
148148

149149
// Select dependencies from packages created before this one
150-
const dependencies = i === 0 ? [] : this.selectDependencies(i, allPackageNames.slice(0, i));
150+
const dependencies =
151+
i === 0 ? [] : this.selectDependencies(i, allPackageNames.slice(0, i));
151152

152153
this.packages.set(packageName, {
153154
name: packageName,
@@ -181,9 +182,15 @@ class MonorepoGenerator {
181182

182183
// Create the scenario: A has build, B doesn't, C has build
183184
const scriptName = this.getRandomElement(this.SCRIPT_NAMES);
184-
pkgA.scripts[scriptName] = this.generateScriptCommand(scriptName, nameA);
185+
pkgA.scripts[scriptName] = this.generateScriptCommand(
186+
scriptName,
187+
nameA,
188+
);
185189
delete pkgB.scripts[scriptName]; // B doesn't have the script
186-
pkgC.scripts[scriptName] = this.generateScriptCommand(scriptName, nameC);
190+
pkgC.scripts[scriptName] = this.generateScriptCommand(
191+
scriptName,
192+
nameC,
193+
);
187194
}
188195
}
189196
}
@@ -201,10 +208,13 @@ class MonorepoGenerator {
201208
version: '1.0.0',
202209
main: 'src/index.js',
203210
scripts: pkg.scripts,
204-
dependencies: pkg.dependencies.reduce((deps, dep) => {
205-
deps[`@monorepo/${dep}`] = 'workspace:*';
206-
return deps;
207-
}, {} as Record<string, string>),
211+
dependencies: pkg.dependencies.reduce(
212+
(deps, dep) => {
213+
deps[`@monorepo/${dep}`] = 'workspace:*';
214+
return deps;
215+
},
216+
{} as Record<string, string>,
217+
),
208218
};
209219

210220
fs.writeFileSync(
@@ -352,11 +362,9 @@ module.exports = { ${pkg.name.replace('-', '_')} };
352362
console.log('\nStatistics:');
353363
console.log(`- Total packages: ${this.packages.size}`);
354364
console.log(
355-
`- Average dependencies per package: ${
356-
(
357-
totalDeps / this.packages.size
358-
).toFixed(2)
359-
}`,
365+
`- Average dependencies per package: ${(
366+
totalDeps / this.packages.size
367+
).toFixed(2)}`,
360368
);
361369
console.log(`- Max dependencies in a package: ${maxDeps}`);
362370
console.log(`- Packages with vite-plus.json: ${packagesWithVitePlus}`);

docs/.vitepress/config.mts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ export default defineConfig({
66
description: 'Vite+',
77
themeConfig: {
88
// https://vitepress.dev/reference/default-theme-config
9-
nav: [
10-
{ text: 'Home', link: '/' },
11-
],
9+
nav: [{ text: 'Home', link: '/' }],
1210

1311
sidebar: [],
1412

dprint.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
"quotes": "preferSingle"
1414
},
1515
"excludes": [
16+
"**/*.ts",
17+
"**/*.tsx",
18+
"**/*.js",
19+
"**/*.jsx",
1620
"crates/fspy_detours_sys/detours",
1721
"pnpm-lock.yaml",
1822
"packages/cli/binding/index.d.ts",

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"install-global-cli": "npm install -g ./packages/global",
1414
"typecheck": "tsc -b tsconfig.json",
1515
"lint": "vite lint --type-aware --threads 4",
16-
"test": "vite test run && pnpm --filter=@voidzero-dev/vite-plus test && pnpm -r snap-test",
16+
"test": "vite test run && pnpm -r snap-test",
1717
"prepare": "husky"
1818
},
1919
"devDependencies": {
@@ -27,14 +27,15 @@
2727
"oxfmt": "catalog:",
2828
"oxlint": "catalog:",
2929
"typescript": "catalog:",
30-
"vitest": "catalog:"
30+
"vitest": "workspace:@voidzero-dev/vite-plus-test@*"
3131
},
3232
"lint-staged": {
33-
"*.@(js|ts|tsx|yml|yaml|md|json|html|toml)": [
33+
"*.@(yml|yaml|md|json|html|toml)": [
3434
"dprint fmt --staged"
3535
],
3636
"*.@(js|ts|tsx)": [
37-
"oxlint -- --fix"
37+
"oxlint -- --fix",
38+
"oxfmt"
3839
],
3940
"*.rs": [
4041
"cargo fmt --"

packages/cli/binding/__tests__/run-command.spec.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,27 @@ test('should run command successfully', async () => {
1818

1919
// write file on the temp directory
2020
test('should write file on the temp directory', async () => {
21-
const tempDir = await fs.realpath(await fs.mkdtemp(path.join(tmpdir(), 'vite-plus-test-')));
21+
const tempDir = await fs.realpath(
22+
await fs.mkdtemp(path.join(tmpdir(), 'vite-plus-test-')),
23+
);
2224
const result = await runCommand({
2325
binName: 'node',
2426
args: ['-e', `fs.writeFileSync("test.txt", "Hello, world!")`],
2527
envs: {},
2628
cwd: tempDir,
2729
});
2830
expect(result).toMatchSnapshot();
29-
expect(await fs.readFile(path.join(tempDir, 'test.txt'), 'utf-8')).toBe('Hello, world!');
31+
expect(await fs.readFile(path.join(tempDir, 'test.txt'), 'utf-8')).toBe(
32+
'Hello, world!',
33+
);
3034
await fs.rm(tempDir, { recursive: true });
3135
});
3236

3337
// read file on the temp directory
3438
test('should read file on the temp directory', async () => {
35-
const tempDir = await fs.realpath(await fs.mkdtemp(path.join(tmpdir(), 'vite-plus-test-')));
39+
const tempDir = await fs.realpath(
40+
await fs.mkdtemp(path.join(tmpdir(), 'vite-plus-test-')),
41+
);
3642
await fs.writeFile(path.join(tempDir, 'test.txt'), 'Hello, world!');
3743
const result = await runCommand({
3844
binName: 'node',
@@ -46,10 +52,15 @@ test('should read file on the temp directory', async () => {
4652

4753
// write and read file on the temp directory
4854
test('should write and read file on the temp directory', async () => {
49-
const tempDir = await fs.realpath(await fs.mkdtemp(path.join(tmpdir(), 'vite-plus-test-')));
55+
const tempDir = await fs.realpath(
56+
await fs.mkdtemp(path.join(tmpdir(), 'vite-plus-test-')),
57+
);
5058
const result = await runCommand({
5159
binName: 'node',
52-
args: ['-e', `fs.writeFileSync("test.txt", "Hello, world!"); fs.readFileSync("test.txt", "utf-8")`],
60+
args: [
61+
'-e',
62+
`fs.writeFileSync("test.txt", "Hello, world!"); fs.readFileSync("test.txt", "utf-8")`,
63+
],
5364
envs: {},
5465
cwd: tempDir,
5566
});

packages/cli/binding/index.d.ts

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,24 @@
1111
*/
1212
export interface CliOptions {
1313
/** Resolver function for the lint tool (oxlint) */
14-
lint: ((err: Error | null, ) => Promise<JsCommandResolvedResult>)
14+
lint: (err: Error | null) => Promise<JsCommandResolvedResult>;
1515
/** Resolver function for the fmt tool (oxfmt) */
16-
fmt: ((err: Error | null, ) => Promise<JsCommandResolvedResult>)
16+
fmt: (err: Error | null) => Promise<JsCommandResolvedResult>;
1717
/** Resolver function for the vite tool (used for build/dev) */
18-
vite: ((err: Error | null, ) => Promise<JsCommandResolvedResult>)
18+
vite: (err: Error | null) => Promise<JsCommandResolvedResult>;
1919
/** Resolver function for the test tool (vitest) */
20-
test: ((err: Error | null, ) => Promise<JsCommandResolvedResult>)
20+
test: (err: Error | null) => Promise<JsCommandResolvedResult>;
2121
/** Resolver function for the lib tool (tsdown) */
22-
lib: ((err: Error | null, ) => Promise<JsCommandResolvedResult>)
22+
lib: (err: Error | null) => Promise<JsCommandResolvedResult>;
2323
/** Resolver function for the doc tool (vitepress) */
24-
doc: ((err: Error | null, ) => Promise<JsCommandResolvedResult>)
24+
doc: (err: Error | null) => Promise<JsCommandResolvedResult>;
2525
/** Optional working directory override */
26-
cwd?: string
26+
cwd?: string;
2727
/** Read the vite.config.ts in the Node.js side and return the `lint` and `fmt` config JSON string back to the Rust side */
28-
resolveUniversalViteConfig: ((err: Error | null, arg: string) => Promise<string>)
28+
resolveUniversalViteConfig: (
29+
err: Error | null,
30+
arg: string,
31+
) => Promise<string>;
2932
}
3033

3134
/**
@@ -53,13 +56,15 @@ export interface CliOptions {
5356
* console.log(`Workspace root: ${result.root}`);
5457
* ```
5558
*/
56-
export declare function detectWorkspace(cwd: string): Promise<DetectWorkspaceResult>
59+
export declare function detectWorkspace(
60+
cwd: string,
61+
): Promise<DetectWorkspaceResult>;
5762

5863
export interface DetectWorkspaceResult {
59-
packageManagerName?: string
60-
packageManagerVersion?: string
61-
isMonorepo: boolean
62-
root?: string
64+
packageManagerName?: string;
65+
packageManagerVersion?: string;
66+
isMonorepo: boolean;
67+
root?: string;
6368
}
6469

6570
/**
@@ -95,20 +100,22 @@ export interface DetectWorkspaceResult {
95100
* console.log(`Package manager version: ${result.version}`);
96101
* ```
97102
*/
98-
export declare function downloadPackageManager(options: DownloadPackageManagerOptions): Promise<DownloadPackageManagerResult>
103+
export declare function downloadPackageManager(
104+
options: DownloadPackageManagerOptions,
105+
): Promise<DownloadPackageManagerResult>;
99106

100107
export interface DownloadPackageManagerOptions {
101-
name: string
102-
version: string
103-
expectedHash?: string
108+
name: string;
109+
version: string;
110+
expectedHash?: string;
104111
}
105112

106113
export interface DownloadPackageManagerResult {
107-
name: string
108-
installDir: string
109-
binPrefix: string
110-
packageName: string
111-
version: string
114+
name: string;
115+
installDir: string;
116+
binPrefix: string;
117+
packageName: string;
118+
version: string;
112119
}
113120

114121
/**
@@ -120,19 +127,19 @@ export interface DownloadPackageManagerResult {
120127
*/
121128
export interface JsCommandResolvedResult {
122129
/** Absolute path to the tool's executable or script */
123-
binPath: string
130+
binPath: string;
124131
/** Environment variables to set when running the tool */
125-
envs: Record<string, string>
132+
envs: Record<string, string>;
126133
}
127134

128135
/** Access modes for a path. */
129136
export interface PathAccess {
130137
/** Whether the path was read */
131-
read: boolean
138+
read: boolean;
132139
/** Whether the path was written */
133-
write: boolean
140+
write: boolean;
134141
/** Whether the path was read as a directory */
135-
readDir: boolean
142+
readDir: boolean;
136143
}
137144

138145
/**
@@ -156,7 +163,7 @@ export interface PathAccess {
156163
* Errors from JavaScript resolvers are converted to specific error types
157164
* (e.g., `LintFailed`, `ViteError`) to provide better error messages.
158165
*/
159-
export declare function run(options: CliOptions): Promise<number>
166+
export declare function run(options: CliOptions): Promise<number>;
160167

161168
/**
162169
* Run a command with fspy tracking, callable from JavaScript.
@@ -192,7 +199,9 @@ export declare function run(options: CliOptions): Promise<number>
192199
* console.log(`Path accesses:`, result.pathAccesses);
193200
* ```
194201
*/
195-
export declare function runCommand(options: RunCommandOptions): Promise<RunCommandResult>
202+
export declare function runCommand(
203+
options: RunCommandOptions,
204+
): Promise<RunCommandResult>;
196205

197206
/**
198207
* Input parameters for running a command with fspy tracking.
@@ -205,13 +214,13 @@ export declare function runCommand(options: RunCommandOptions): Promise<RunComma
205214
*/
206215
export interface RunCommandOptions {
207216
/** The name of the binary to execute */
208-
binName: string
217+
binName: string;
209218
/** Command line arguments to pass to the binary */
210-
args: Array<string>
219+
args: Array<string>;
211220
/** Environment variables to set when executing the command */
212-
envs: Record<string, string>
221+
envs: Record<string, string>;
213222
/** The current working directory for the command */
214-
cwd: string
223+
cwd: string;
215224
}
216225

217226
/**
@@ -223,7 +232,7 @@ export interface RunCommandOptions {
223232
*/
224233
export interface RunCommandResult {
225234
/** The exit code of the command */
226-
exitCode: number
235+
exitCode: number;
227236
/** Map of relative paths to their access modes */
228-
pathAccesses: Record<string, PathAccess>
237+
pathAccesses: Record<string, PathAccess>;
229238
}

0 commit comments

Comments
 (0)