fix(vite): improve commonjs handling (#3336)

Fixes https://github.com/denoland/fresh/issues/3323
This commit is contained in:
Marvin Hagemeister
2025-09-04 12:59:13 +02:00
committed by GitHub
parent b94aab2a1a
commit 4138b8ca66
17 changed files with 1096 additions and 218 deletions
+36
View File
@@ -86,6 +86,42 @@ export async function launchDevServer(
);
}
export async function spawnDevServer(
dir: string,
env: Record<string, string> = {},
) {
const boot = Promise.withResolvers<void>();
const p = Promise.withResolvers<void>();
let serverAddress = "";
const server = withChildProcessServer(
{
cwd: dir,
args: ["run", "-A", "--cached-only", "npm:vite", "--port", "0"],
env,
},
async (address) => {
serverAddress = address;
boot.resolve();
await p.promise;
},
);
await boot.promise;
return {
dir,
promise: server,
address: () => {
return serverAddress;
},
async [Symbol.asyncDispose]() {
await p.resolve();
},
};
}
export async function withDevServer(
fixtureDir: string,
fn: (address: string, dir: string) => void | Promise<void>,