Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,13 @@ check:
watch-check:
just watch "'cargo check; cargo clippy'"

[unix]
test:
cargo test $(for d in crates/*/; do echo -n "-p $(basename $d) "; done) -p vite-plus-cli

[windows]
test:
cargo test
$packages = Get-ChildItem -Path crates -Directory | ForEach-Object { '-p'; $_.Name }; $Env:__COMPAT_LAYER='RunAsInvoker'; cargo test @packages -p vite-plus-cli

lint:
cargo clippy --workspace --all-targets --all-features -- --deny warnings
Expand Down
2 changes: 1 addition & 1 deletion packages/core/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { dts } from 'rolldown-plugin-dts';
import { glob } from 'tinyglobby';

import { generateLicenseFile } from '../../scripts/generate-license.js';
import viteRolldownConfig from '../../vite/packages/vite/rolldown.config.js';
import { buildCjsDeps } from './build-support/build-cjs-deps.js';
import { replaceThirdPartyCjsRequires } from './build-support/find-create-require.js';
import { RewriteImportsPlugin } from './build-support/rewrite-imports.js';
Expand All @@ -26,7 +27,6 @@ import {
type ReplacementRule,
} from './build-support/rewrite-module-specifiers.js';
import pkgJson from './package.json' with { type: 'json' };
import viteRolldownConfig from './vite-rolldown.config.js';

const projectDir = join(fileURLToPath(import.meta.url), '..');

Expand Down
1 change: 0 additions & 1 deletion packages/core/rollupLicensePlugin.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/core/vite-rolldown.config.ts

This file was deleted.

118 changes: 111 additions & 7 deletions packages/tools/src/install-global-cli.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { execSync } from 'node:child_process';
import { execFileSync, execSync } from 'node:child_process';
import {
existsSync,
lstatSync,
mkdirSync,
mkdtempSync,
readFileSync,
readdirSync,
realpathSync,
rmSync,
rmdirSync,
symlinkSync,
writeFileSync,
} from 'node:fs';
Expand Down Expand Up @@ -105,11 +108,20 @@ export function installGlobalCli() {

// Clean up old local-dev directories to avoid accumulation
if (existsSync(installDir)) {
const currentInstallPath = getCurrentInstallPath(installDir);
for (const entry of readdirSync(installDir)) {
if (entry.startsWith(LOCAL_DEV_PREFIX)) {
const entryPath = path.join(installDir, entry);
if (pathsEqual(entryPath, currentInstallPath)) {
continue;
}
try {
rmSync(path.join(installDir, entry), { recursive: true, force: true });
removeInstallPath(entryPath);
} catch (err) {
if (isWindowsLockedExecutableError(err)) {
console.log(`Skipping old ${entry} because its vp.exe is still running.`);
continue;
}
console.warn(`Warning: failed to remove old ${entry}: ${(err as Error).message}`);
}
}
Expand All @@ -132,12 +144,17 @@ export function installGlobalCli() {
// Run platform-specific install script (use absolute paths)
const installScriptDir = path.join(repoRoot, 'packages/cli');
if (isWindows) {
// Use pwsh (PowerShell Core) for better UTF-8 handling
// Prefer PowerShell Core for better UTF-8 handling, but fall back to
// Windows PowerShell because pwsh is not available on every Windows host.
const ps1Path = path.join(installScriptDir, 'install.ps1');
execSync(`pwsh -ExecutionPolicy Bypass -File "${ps1Path}"`, {
stdio: 'inherit',
env,
});
execFileSync(
getWindowsPowerShellCommand(),
['-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', ps1Path],
{
stdio: 'inherit',
env,
},
);
} else {
const shPath = path.join(installScriptDir, 'install.sh');
execSync(`bash "${shPath}"`, {
Expand Down Expand Up @@ -171,6 +188,73 @@ function getTargetDirs(): string[] {
return dirs;
}

function removeInstallPath(targetPath: string) {
if (!isWindows) {
rmSync(targetPath, { recursive: true, force: true });
return;
}

removeWindowsPath(targetPath);
}

function getCurrentInstallPath(installDir: string): string | undefined {
const currentPath = path.join(installDir, 'current');
if (!existsSync(currentPath)) {
return undefined;
}

try {
return realpathSync(currentPath);
} catch {
return undefined;
}
}

function pathsEqual(a: string, b: string | undefined): boolean {
if (!b) {
return false;
}

const resolvedA = path.resolve(a);
const resolvedB = path.resolve(b);
return isWindows ? resolvedA.toLowerCase() === resolvedB.toLowerCase() : resolvedA === resolvedB;
}

function isWindowsLockedExecutableError(err: unknown): boolean {
if (!isWindows || !(err instanceof Error)) {
return false;
}

const code = (err as NodeJS.ErrnoException).code;
return (
(code === 'EPERM' || code === 'EBUSY') &&
err.message.includes(`${path.sep}bin${path.sep}vp.exe`)
);
}
Comment thread
fengmk2 marked this conversation as resolved.

function removeWindowsPath(targetPath: string) {
let stat;
try {
stat = lstatSync(targetPath);
} catch (err) {
if ((err as NodeJS.ErrnoException).code === 'ENOENT') {
return;
}
throw err;
}
Comment thread
fengmk2 marked this conversation as resolved.

if (!stat.isDirectory() || stat.isSymbolicLink()) {
rmSync(targetPath, { force: true });
return;
}

for (const entry of readdirSync(targetPath)) {
removeWindowsPath(path.join(targetPath, entry));
}

rmdirSync(targetPath);
}

// Find the vp binary in the target directory.
// Checks target/release/ first (local builds), then target/<triple>/release/ (cross-compiled CI builds).
function findVpBinary(binaryName: string) {
Expand All @@ -195,6 +279,26 @@ function findVpBinary(binaryName: string) {
return null;
}

function getWindowsPowerShellCommand(): string {
for (const command of ['pwsh', 'powershell.exe', 'powershell']) {
try {
const resolved = execFileSync('where.exe', [command], {
encoding: 'utf-8',
stdio: 'pipe',
})
.split(/\r?\n/)
.find(Boolean);
if (resolved) {
return resolved;
}
} catch {
// Try the next candidate.
}
}

return 'powershell.exe';
}

/**
* Install dependencies for CI by generating a wrapper package.json with file: protocol
* references to the main tgz and sibling @voidzero-dev/* tgz files, then running npm install.
Expand Down
5 changes: 1 addition & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@
"packages/cli/docs",
"packages/cli/snap-tests",
"packages/cli/snap-tests-global",
// Symlinks to vite submodule files that don't use .js extensions;
// excluding build.ts too because it imports vite-rolldown.config.ts
// build.ts imports vite/packages/vite/rolldown.config.ts which doesn't use .js extensions
"packages/core/build.ts",
"packages/core/rollupLicensePlugin.ts",
"packages/core/vite-rolldown.config.ts",
"vite",
"rolldown",
"target"
Expand Down
4 changes: 0 additions & 4 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ export default defineConfig({
'bench/**/*.ts',
'ecosystem-ci/**/*',
'packages/*/build.ts',
'packages/core/rollupLicensePlugin.ts',
'packages/core/vite-rolldown.config.ts',
'packages/tools/**/*.ts',
],
rules: {
Expand All @@ -48,8 +46,6 @@ export default defineConfig({
'**/snap-tests-global/**',
'**/snap-tests-todo/**',
'packages/*/binding/**',
'packages/core/rollupLicensePlugin.ts',
'packages/core/vite-rolldown.config.ts',
],
},
test: {
Expand Down
Loading