fix(core): lazy-load child_process to prevent browser bundling
- Move spawn import in git-checkout.ts to lazy require() to prevent
node:child_process from being included in browser bundles
- Add ./git-checkout subpath export in package.json
- Update project-workspace.ts to use direct subpath import
- Update test mock to match new import path
Fixes: Vite crash from child_process externalization error,
API crashloop from missing readGitCheckout export
This commit is contained in:
parent
bd3c6c2d47
commit
fccb4cc6c7
@ -38,6 +38,11 @@
|
||||
"types": "./src/node/screen-capability.ts",
|
||||
"development": "./src/node/screen-capability.ts",
|
||||
"default": "./src/node/screen-capability.ts"
|
||||
},
|
||||
"./git-checkout": {
|
||||
"types": "./src/git-checkout.ts",
|
||||
"development": "./src/git-checkout.ts",
|
||||
"default": "./src/git-checkout.ts"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
|
||||
@ -1,9 +1,16 @@
|
||||
import { spawn } from "node:child_process";
|
||||
import { access } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { gitStatusArgv, gitUntrackedFilesArgv, parseGitNameOnly } from "./compose-update.js";
|
||||
import { DEFAULT_UPDATE_REMOTE, parseGitStatusPorcelain } from "./self-update.js";
|
||||
|
||||
// Lazy import to avoid bundling `node:child_process` in browser bundles.
|
||||
// `defaultGitRunner` is server-only; lazy-loading ensures tree-shaking works.
|
||||
let _spawn: typeof import("node:child_process").spawn | null = null;
|
||||
const getSpawn = (): typeof import("node:child_process").spawn => {
|
||||
if (!_spawn) _spawn = require("node:child_process").spawn;
|
||||
return _spawn;
|
||||
};
|
||||
|
||||
export interface GitCheckoutStatus {
|
||||
present: boolean;
|
||||
remoteUrl: string | null;
|
||||
@ -22,6 +29,7 @@ export type GitRunner = (args: string[], cwd: string) => Promise<GitRunnerResult
|
||||
|
||||
export async function defaultGitRunner(args: string[], cwd: string): Promise<GitRunnerResult> {
|
||||
return new Promise((resolve) => {
|
||||
const spawn = getSpawn();
|
||||
const child = spawn("git", args, { cwd, env: process.env });
|
||||
let output = "";
|
||||
child.stdout.on("data", (chunk: Buffer | string) => {
|
||||
|
||||
@ -18,7 +18,6 @@ export * from "./computer-updates.js";
|
||||
export * from "./cron.js";
|
||||
export * from "./events.js";
|
||||
export * from "./featured-connectors.js";
|
||||
export * from "./git-checkout.js";
|
||||
export * from "./group-mentions.js";
|
||||
export * from "./http-response.js";
|
||||
export * from "./mcp.js";
|
||||
|
||||
@ -10,7 +10,7 @@ import {
|
||||
wireProjectWorkspace,
|
||||
} from "./project-workspace.js";
|
||||
|
||||
vi.mock("@rakazo/core", () => ({
|
||||
vi.mock("@rakazo/core/git-checkout.js", () => ({
|
||||
readGitCheckout: vi.fn(async () => ({
|
||||
present: true,
|
||||
remoteUrl: "https://github.com/example/demo.git",
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { access, stat } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { readGitCheckout } from "@rakazo/core";
|
||||
import { readGitCheckout } from "@rakazo/core/git-checkout";
|
||||
import type { PrismaClient } from "./client.js";
|
||||
|
||||
export class InvalidProjectWorkspacePathError extends Error {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user