Skip to content

Commit 6c76830

Browse files
committed
fix: copy .node NAPI bindings to binding/ instead of dist/
After merging packages/global into packages/cli, the NAPI loader at binding/index.cjs uses require('./vite-plus.*.node') relative to itself, so .node files must live in binding/ not dist/.
1 parent 8ef81c7 commit 6c76830

3 files changed

Lines changed: 24 additions & 21 deletions

File tree

crates/vite_global_cli/src/commands/upgrade/install.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,19 @@ const MAIN_PACKAGE_ENTRIES: &[&str] =
3434
///
3535
/// From the platform tarball, extracts:
3636
/// - The `vp` binary → `{version_dir}/bin/vp`
37-
/// - Any `.node` files → `{version_dir}/dist/`
37+
/// - Any `.node` files → `{version_dir}/binding/`
3838
pub async fn extract_platform_package(
3939
tgz_data: &[u8],
4040
version_dir: &AbsolutePath,
4141
) -> Result<(), Error> {
4242
let bin_dir = version_dir.join("bin");
43-
let dist_dir = version_dir.join("dist");
43+
let binding_dir = version_dir.join("binding");
4444
tokio::fs::create_dir_all(&bin_dir).await?;
45-
tokio::fs::create_dir_all(&dist_dir).await?;
45+
tokio::fs::create_dir_all(&binding_dir).await?;
4646

4747
let data = tgz_data.to_vec();
4848
let bin_dir_clone = bin_dir.clone();
49-
let dist_dir_clone = dist_dir.clone();
49+
let binding_dir_clone = binding_dir.clone();
5050

5151
tokio::task::spawn_blocking(move || {
5252
let cursor = Cursor::new(data);
@@ -81,8 +81,8 @@ pub async fn extract_platform_package(
8181
std::fs::set_permissions(&target, std::fs::Permissions::from_mode(0o755))?;
8282
}
8383
} else if file_name.ends_with(".node") {
84-
// .node NAPI files go to dist/
85-
let target = dist_dir_clone.join(file_name);
84+
// .node NAPI files go to binding/ (alongside index.cjs loader)
85+
let target = binding_dir_clone.join(file_name);
8686
let mut buf = Vec::new();
8787
entry.read_to_end(&mut buf)?;
8888
std::fs::write(&target, &buf)?;

packages/cli/install.ps1

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -285,13 +285,15 @@ function Main {
285285
$VersionDir = "$InstallDir\$ViteVersion"
286286
$BinDir = "$VersionDir\bin"
287287
$DistDir = "$VersionDir\dist"
288+
$BindingDir = "$VersionDir\binding"
288289
$CurrentLink = "$InstallDir\current"
289290

290291
$binaryName = "vp.exe"
291292

292293
# Create directories
293294
New-Item -ItemType Directory -Force -Path $BinDir | Out-Null
294295
New-Item -ItemType Directory -Force -Path $DistDir | Out-Null
296+
New-Item -ItemType Directory -Force -Path $BindingDir | Out-Null
295297

296298
# Download and extract native binary and .node files from platform package
297299
# Also copy JS bundle and assets
@@ -315,14 +317,14 @@ function Main {
315317
Write-Error-Exit "VITE_PLUS_LOCAL_BINARY must be set when using VITE_PLUS_LOCAL_TGZ"
316318
}
317319

318-
# Copy .node files if present
319-
$nodeFilesPath = Join-Path $tempExtract "package" "dist"
320+
# Copy .node files if present (NAPI bindings go to binding/ alongside index.cjs loader)
321+
$nodeFilesPath = Join-Path $tempExtract "package" "binding"
320322
Get-ChildItem -Path $nodeFilesPath -Filter "*.node" -ErrorAction SilentlyContinue | ForEach-Object {
321-
$destFile = Join-Path $DistDir $_.Name
323+
$destFile = Join-Path $BindingDir $_.Name
322324
if (Test-Path $destFile) {
323325
Remove-Item -Path $destFile -Force
324326
}
325-
Copy-Item -Path $_.FullName -Destination $DistDir -Force
327+
Copy-Item -Path $_.FullName -Destination $BindingDir -Force
326328
}
327329

328330
# Copy JS assets
@@ -358,14 +360,14 @@ function Main {
358360
Copy-Item -Path $binarySource -Destination $BinDir -Force
359361
}
360362

361-
# Copy .node files to DistDir (delete existing first to avoid system cache issues)
363+
# Copy .node files to BindingDir (delete existing first to avoid system cache issues)
362364
$nodeFilesPath = Join-Path $platformTempExtract "package"
363365
Get-ChildItem -Path $nodeFilesPath -Filter "*.node" -ErrorAction SilentlyContinue | ForEach-Object {
364-
$destFile = Join-Path $DistDir $_.Name
366+
$destFile = Join-Path $BindingDir $_.Name
365367
if (Test-Path $destFile) {
366368
Remove-Item -Path $destFile -Force
367369
}
368-
Copy-Item -Path $_.FullName -Destination $DistDir -Force
370+
Copy-Item -Path $_.FullName -Destination $BindingDir -Force
369371
}
370372

371373
Remove-Item -Recurse -Force $platformTempExtract

packages/cli/install.sh

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ main() {
539539
VERSION_DIR="$INSTALL_DIR/$VITE_PLUS_VERSION"
540540
BIN_DIR="$VERSION_DIR/bin"
541541
DIST_DIR="$VERSION_DIR/dist"
542+
BINDING_DIR="$VERSION_DIR/binding"
542543
CURRENT_LINK="$INSTALL_DIR/current"
543544

544545
local binary_name="vp"
@@ -547,7 +548,7 @@ main() {
547548
fi
548549

549550
# Create directories
550-
mkdir -p "$BIN_DIR" "$DIST_DIR"
551+
mkdir -p "$BIN_DIR" "$DIST_DIR" "$BINDING_DIR"
551552

552553
# Download and extract native binary and .node files from platform package
553554
# Also copy JS bundle and assets
@@ -570,11 +571,11 @@ main() {
570571
fi
571572
chmod +x "$BIN_DIR/$binary_name"
572573

573-
# Copy .node files if present
574-
for node_file in "$temp_dir"/dist/*.node; do
574+
# Copy .node files if present (NAPI bindings go to binding/ alongside index.cjs loader)
575+
for node_file in "$temp_dir"/binding/*.node; do
575576
if [ -f "$node_file" ]; then
576-
rm -f "$DIST_DIR/$(basename "$node_file")"
577-
cp "$node_file" "$DIST_DIR/"
577+
rm -f "$BINDING_DIR/$(basename "$node_file")"
578+
cp "$node_file" "$BINDING_DIR/"
578579
fi
579580
done
580581

@@ -602,10 +603,10 @@ main() {
602603
cp "$platform_temp_dir/$binary_name" "$BIN_DIR/"
603604
chmod +x "$BIN_DIR/$binary_name"
604605

605-
# Copy .node files to DIST_DIR (delete existing first to avoid system cache issues)
606+
# Copy .node files to BINDING_DIR (delete existing first to avoid system cache issues)
606607
for node_file in "$platform_temp_dir"/*.node; do
607-
rm -f "$DIST_DIR/$(basename "$node_file")"
608-
cp "$node_file" "$DIST_DIR/"
608+
rm -f "$BINDING_DIR/$(basename "$node_file")"
609+
cp "$node_file" "$BINDING_DIR/"
609610
done
610611
rm -rf "$platform_temp_dir"
611612

0 commit comments

Comments
 (0)