Files
dev-desktop/scripts/lib/cli-external-packages.ts
zeekayandHanzo Dev c24e700a18 feat(desktop): complete 100% Tauri v2 migration, native SnapShot/SSH/updater/CLI/preview, standalone bundles & CI
Finishes migrating Hanzo Dev off Electron to native Rust Tauri v2:
- Native Rust SnapShot capture (snapshot.rs), direct SSH port-forward supervisor (ssh.rs), GitHub release updater, ~/.local/bin/hanzo-dev-app CLI installer, global shortcuts (CmdOrCtrl+Shift+I/J/2), macOS Dock Reopen restore, and Tauri preview iframe host.
- Self-contained .app/.dmg/.AppImage/.exe/.msi resource staging via apps/desktop/scripts/stage-tauri-resources.mjs + tauri.conf.json.
- Migrates all GitHub Actions CI & release workflows (.github/workflows/*) to Rust + Tauri v2 and purges all @electron/* dependencies and legacy Electron packaging scripts.
- Cleans unused web/mobile deps so knip passes with zero issues across all 43 workspaces.

Co-authored-by: Hanzo Dev <[email protected]>
2026-11-19 11:37:00 -08:00

92 lines
2.9 KiB
TypeScript

/** Keep bundler externals and staged runtime dependency roots aligned. */
// Filesystem-loaded externals need dependencies outside the bundle.
const CLI_RUNTIME_EXTERNAL_PREFIXES = [
// Cursor ships computed Webpack imports and platform helper packages.
"@cursor/sdk",
// Playwright reads package.json and browsers.json beside its runtime modules.
"playwright-core",
"node-pty",
"ffi-rs",
"@yuuang/",
"@ff-labs/",
"transcribe-cpp",
"@transcribe-cpp/",
"koffi",
"@koromix/",
"@napi-rs/keyring",
"node-gyp-build",
"node-addon-api",
"bufferutil",
"utf-8-validate",
] as const;
// Match Cursor dependency boundaries so zod does not externalize zod-to-json-schema.
const CURSOR_RUNTIME_DEPENDENCIES = [
"@bufbuild/protobuf",
"@connectrpc/connect",
"@connectrpc/connect-node",
"@connectrpc/connect-web",
"@statsig/js-client",
"@statsig/client-core",
"zod",
"undici",
"@fastify/busboy",
] as const;
export function isRuntimeExternalCliDependency(id: string): boolean {
return (
CLI_RUNTIME_EXTERNAL_PREFIXES.some((prefix) => id.startsWith(prefix)) ||
CURSOR_RUNTIME_DEPENDENCIES.some((name) => id === name || id.startsWith(`${name}/`))
);
}
/** Use neverBundle: false from alwaysBundle means no opinion and leaves transitive packages bundled. */
export function isExternalCliDependency(id: string): boolean {
return isRuntimeExternalCliDependency(id);
}
export function shouldBundleCliDependency(id: string): boolean {
if (id.startsWith("node:")) return false;
return !isExternalCliDependency(id);
}
export function selectCliRuntimeExternalDependencies(
dependencies: Readonly<Record<string, string>>,
): Record<string, string> {
return Object.fromEntries(
Object.entries(dependencies).filter(([name]) => isRuntimeExternalCliDependency(name)),
);
}
/** regionCount distinguishes a clean bundle from a changed marker format the scan cannot see. */
export function findInlinedExternalPackages(source: string): {
readonly regionCount: number;
readonly inlined: ReadonlyArray<string>;
readonly inlinedPackages: ReadonlyArray<string>;
} {
// Rolldown marks each inlined module with a `//#region <path>` line; newer
// releases (vite-plus 1.4) emit a bare `// <path>` line instead.
const regionPattern = /^\/\/(?:#region)?[ \t]+(\S+)[ \t]*$/gm;
const packagePattern = /node_modules\/((?:@[^/\s]+\/)?[^/\s]+)\//g;
let regionCount = 0;
const inlined = new Set<string>();
const inlinedPackages = new Set<string>();
for (const region of source.matchAll(regionPattern)) {
regionCount += 1;
const regionPath = region[1] ?? "";
for (const candidate of regionPath.matchAll(packagePattern)) {
const name = candidate[1];
if (name === undefined || name === ".pnpm") continue;
inlinedPackages.add(name);
if (isExternalCliDependency(name)) inlined.add(name);
}
}
return {
regionCount,
inlined: [...inlined].sort(),
inlinedPackages: [...inlinedPackages].sort(),
};
}