MCPcopy Create free account
hub / github.com/vercel/vercel / doInstallInjectedDevPackage

Function doInstallInjectedDevPackage

packages/python/src/start-dev-server.ts:338–426  ·  view source on GitHub ↗
(
  pkg: InjectedPackageSpec,
  opts: DevPythonOptions & { targetDir: string }
)

Source from the content-addressed store, hash-verified

336}
337
338async function doInstallInjectedDevPackage(
339 pkg: InjectedPackageSpec,
340 opts: DevPythonOptions & { targetDir: string }
341): Promise<void> {
342 const { targetDir, workPath, uvPath, pythonBin, env, onStdout, onStderr } =
343 opts;
344 mkdirSync(targetDir, { recursive: true });
345
346 const localDir = join(__dirname, '..', '..', '..', 'python', pkg.name);
347 const isLocalDev = existsSync(join(localDir, 'pyproject.toml'));
348
349 const dep =
350 pkg.envOverride ||
351 (isLocalDev ? localDir : `${pkg.name}==${pkg.pinnedVersion}`);
352
353 // Skip install if the exact pypi version is already present;
354 // local dev builds and explicitly specified versions
355 // always reinstall to pick up possible source changes.
356 if (!isLocalDev && !pkg.envOverride) {
357 const distInfoName = pkg.name.replace('-', '_');
358 const distInfo = join(
359 targetDir,
360 `${distInfoName}-${pkg.pinnedVersion}.dist-info`
361 );
362 if (existsSync(distInfo)) {
363 debug(`${pkg.name} ${pkg.pinnedVersion} already installed, skipping`);
364 return;
365 }
366 }
367
368 debug(
369 `Installing ${pkg.name} into ${targetDir} (type: ${isLocalDev ? 'local' : 'pypi'}, source: ${dep})`
370 );
371
372 const pip = uvPath
373 ? { cmd: uvPath, prefix: ['pip', 'install'] }
374 : { cmd: pythonBin, prefix: ['-m', 'pip', 'install'] };
375
376 // Override exclude-newer so a project-level date constraint doesn't
377 // block installation of a recently-published injected package.
378 const excludeOverride = uvPath
379 ? ['--exclude-newer-package', `${pkg.name}=false`]
380 : [];
381
382 const spawnArgs = [
383 ...pip.prefix,
384 '--target',
385 targetDir,
386 ...excludeOverride,
387 dep,
388 ];
389
390 await new Promise<void>((resolve, reject) => {
391 const child = spawn(pip.cmd, spawnArgs, {
392 cwd: workPath,
393 env: getProtectedUvEnv(env),
394 stdio: ['inherit', 'pipe', 'pipe'],
395 });

Callers 1

Calls 8

debugFunction · 0.90
getProtectedUvEnvFunction · 0.90
spawnFunction · 0.85
onStdoutFunction · 0.85
onStderrFunction · 0.85
replaceMethod · 0.80
resolveFunction · 0.50
toStringMethod · 0.45

Tested by

no test coverage detected