Skip to content

Commit 45ba3f9

Browse files
committed
feat(dev): add post-clone setup and bootstrap flow
1 parent 5a628c0 commit 45ba3f9

File tree

5 files changed

+338
-35
lines changed

5 files changed

+338
-35
lines changed

CONTRIBUTING.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
1717
cargo install cargo-binstall
1818
```
1919

20-
Initial setup to install dependencies for Vite+:
20+
Initial setup to prepare the repo for local development:
2121

2222
```
23-
just init
23+
pnpm install:dev
2424
```
2525

2626
### Windows
@@ -37,10 +37,10 @@ Install Rust & Cargo from [rustup.rs](https://rustup.rs/), then install `cargo-b
3737
cargo install cargo-binstall
3838
```
3939

40-
Initial setup to install dependencies for Vite+:
40+
Initial setup to prepare the repo for local development:
4141

4242
```powershell
43-
just init
43+
pnpm install:dev
4444
```
4545

4646
**Note:** Run commands in PowerShell or Windows Terminal. Some commands may require elevated permissions.
@@ -56,13 +56,19 @@ just build
5656
## Local CLI workflow
5757

5858
```
59-
pnpm install
60-
pnpm build:cli
59+
pnpm bootstrap:dev
6160
pnpm test
6261
```
6362

64-
This installs dependencies, builds the repo-local CLI artifacts, and runs tests without reading `~/.vite-plus`.
65-
If you have not prepared the local `rolldown/` and `vite/` checkouts yet, run `just init` or `node packages/tools/src/index.ts sync-remote` first.
63+
This prepares the local `rolldown/` and `vite/` checkouts, installs dependencies, builds the repo-local CLI artifacts, and runs tests without reading `~/.vite-plus`.
64+
65+
If you only want to prepare the repo after cloning it, run:
66+
67+
```
68+
pnpm install:dev
69+
```
70+
71+
If you prefer the existing Just-based setup, `just init` now delegates to the same repo-local install flow.
6672

6773
## Install the Vite+ Global CLI from source code
6874

justfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ _clean_dist:
1818

1919
init: _clean_dist
2020
cargo binstall watchexec-cli cargo-insta typos-cli cargo-shear dprint taplo-cli -y
21-
node packages/tools/src/index.ts sync-remote
22-
pnpm install
21+
pnpm install:dev
2322
pnpm -C docs install
2423

2524
build:

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
"type": "module",
66
"scripts": {
77
"build": "pnpm -F @voidzero-dev/* -F vite-plus build",
8+
"install:dev": "node scripts/setup-local-dev.mjs",
9+
"bootstrap:dev": "pnpm install:dev && pnpm build:cli",
810
"build:cli": "tool build-local-cli",
9-
"bootstrap-cli": "tool build-local-cli --release-rust && pnpm install-global-cli",
11+
"bootstrap-cli": "pnpm install:dev && tool build-local-cli --release-rust && pnpm install-global-cli",
1012
"bootstrap-cli:ci": "pnpm install-global-cli",
1113
"install-global-cli": "tool install-global-cli",
1214
"tsgo": "tsgo -b tsconfig.json",

packages/tools/src/local-cli.ts

Lines changed: 65 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { spawnSync } from 'node:child_process';
2-
import { existsSync, mkdirSync } from 'node:fs';
2+
import { copyFileSync, existsSync, mkdirSync, readFileSync } from 'node:fs';
33
import { createRequire } from 'node:module';
44
import path from 'node:path';
55
import { fileURLToPath } from 'node:url';
@@ -13,8 +13,11 @@ const localVpPath = path.join(repoRoot, 'target', 'debug', isWindows ? 'vp.exe'
1313
const localVpBinDir = path.dirname(localVpPath);
1414
const viteRepoDir = path.join(repoRoot, 'vite');
1515
const legacyViteRepoDir = path.join(repoRoot, 'rolldown-vite');
16+
const rolldownSrcDir = path.join(repoRoot, 'rolldown', 'packages', 'rolldown', 'src');
1617
const toolBinPath = path.join(path.dirname(fileURLToPath(import.meta.url)), 'bin.js');
1718
const buildHint = 'pnpm build:cli';
19+
const bootstrapHint = 'pnpm bootstrap:dev';
20+
const installHint = 'pnpm install:dev';
1821
const pnpmExecPath = process.env.npm_execpath;
1922
const pnpmBin = isWindows ? 'pnpm.cmd' : 'pnpm';
2023
const cargoBin = isWindows ? 'cargo.exe' : 'cargo';
@@ -30,7 +33,7 @@ type CommandOptions = {
3033

3134
function failMissing(pathname: string, description: string): never {
3235
console.error(`Missing ${description}: ${pathname}`);
33-
console.error(`Run "${buildHint}" first.`);
36+
console.error(`Run "${bootstrapHint}" from a fresh clone, or "${buildHint}" after setup.`);
3437
process.exit(1);
3538
}
3639

@@ -126,6 +129,51 @@ function rolldownBindingCandidates() {
126129
}
127130
}
128131

132+
function hasRolldownPackagedBinding() {
133+
const candidates = rolldownBindingCandidates();
134+
if (candidates.length === 0) {
135+
return true;
136+
}
137+
138+
for (const candidate of candidates) {
139+
try {
140+
requireFromRolldown.resolve(candidate);
141+
return true;
142+
} catch {
143+
continue;
144+
}
145+
}
146+
147+
return false;
148+
}
149+
150+
function materializeRolldownPackagedBindings() {
151+
for (const candidate of rolldownBindingCandidates()) {
152+
let packageJsonPath: string;
153+
try {
154+
packageJsonPath = requireFromRolldown.resolve(candidate);
155+
} catch {
156+
continue;
157+
}
158+
159+
const packageDir = path.dirname(packageJsonPath);
160+
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8')) as {
161+
files?: string[];
162+
main?: string;
163+
};
164+
const bindingFile = packageJson.main ?? packageJson.files?.find((file) => file.endsWith('.node'));
165+
if (!bindingFile) {
166+
continue;
167+
}
168+
169+
const sourcePath = path.join(packageDir, bindingFile);
170+
const targetPath = path.join(rolldownSrcDir, path.basename(bindingFile));
171+
if (!existsSync(targetPath)) {
172+
copyFileSync(sourcePath, targetPath);
173+
}
174+
}
175+
}
176+
129177
function ensureBuildWorkspaceReady() {
130178
if (!existsSync(viteRepoDir)) {
131179
console.error(`Missing local vite checkout: ${viteRepoDir}`);
@@ -134,34 +182,15 @@ function ensureBuildWorkspaceReady() {
134182
`Found legacy checkout at ${legacyViteRepoDir}. This repo now expects the upstream Vite checkout at ./vite.`,
135183
);
136184
console.error(
137-
'Run "node packages/tools/src/index.ts sync-remote" to recreate the canonical layout.',
185+
`Run "${installHint}" to recreate the canonical layout.`,
138186
);
139187
} else {
140188
console.error(
141-
'Run "node packages/tools/src/index.ts sync-remote" to fetch the local upstream checkouts required for development.',
189+
`Run "${installHint}" to fetch the local upstream checkouts, or "${bootstrapHint}" to prepare and build the local CLI.`,
142190
);
143191
}
144192
process.exit(1);
145193
}
146-
147-
const candidates = rolldownBindingCandidates();
148-
if (candidates.length === 0) {
149-
return;
150-
}
151-
152-
for (const candidate of candidates) {
153-
try {
154-
requireFromRolldown.resolve(candidate);
155-
return;
156-
} catch {
157-
continue;
158-
}
159-
}
160-
161-
console.error('Missing local rolldown native binding dependency.');
162-
console.error('Run "pnpm install" from the repo root to install workspace optional dependencies.');
163-
console.error('If your environment cannot download the prebuilt binding, install "cmake" to build rolldown from source.');
164-
process.exit(1);
165194
}
166195

167196
function runCommand(step: string, command: string, args: string[], options: CommandOptions = {}) {
@@ -237,8 +266,20 @@ export function runBuildLocalCli(args: string[]) {
237266
ensureBuildWorkspaceReady();
238267

239268
runPnpmCommand('Build @rolldown/pluginutils', ['--filter', '@rolldown/pluginutils', 'build']);
269+
const hasPackagedBinding = hasRolldownPackagedBinding();
270+
if (!hasPackagedBinding) {
271+
runPnpmCommand(
272+
'Build rolldown native binding',
273+
['--filter', 'rolldown', releaseRust ? 'build-binding:release' : 'build-binding'],
274+
{
275+
hint: 'If this fails, install "cmake" so rolldown can build its native binding from source.',
276+
},
277+
);
278+
} else {
279+
materializeRolldownPackagedBindings();
280+
}
240281
runPnpmCommand('Build rolldown JS glue', ['--filter', 'rolldown', 'build-node'], {
241-
hint: 'If this fails with a missing rolldown native binding, rerun "pnpm install". If the error mentions "cmake", install cmake to build rolldown from source.',
282+
hint: 'If this fails with a missing rolldown native binding, rerun "pnpm install:dev". If the error mentions "cmake", install cmake to build rolldown from source.',
242283
});
243284
runPnpmCommand('Build vite rolled-up types', ['-C', 'vite', '--filter', 'vite', 'build-types-roll'], {
244285
hint: 'If this fails because vite dependencies are missing, rerun "pnpm install" from the repo root.',

0 commit comments

Comments
 (0)