Home / Function/ runInstallCommand() — astro Function Reference

runInstallCommand() — astro Function Reference

Architecture documentation for the runInstallCommand() function in install.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  8ead6057_5859_6216_20f8_df5dd46a876a["runInstallCommand()"]
  d4f6ce6d_9b1b_5434_0914_2c212e0aee90["install.ts"]
  8ead6057_5859_6216_20f8_df5dd46a876a -->|defined in| d4f6ce6d_9b1b_5434_0914_2c212e0aee90
  39ce6eb0_d5e5_44df_8a2f_689d819ba902["install()"]
  39ce6eb0_d5e5_44df_8a2f_689d819ba902 -->|calls| 8ead6057_5859_6216_20f8_df5dd46a876a
  36456fe7_59f6_7fdf_0458_2f92922a23b0["ensureYarnLock()"]
  8ead6057_5859_6216_20f8_df5dd46a876a -->|calls| 36456fe7_59f6_7fdf_0458_2f92922a23b0
  style 8ead6057_5859_6216_20f8_df5dd46a876a fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/upgrade/src/actions/install.ts lines 119–197

async function runInstallCommand(
	ctx: Pick<Context, 'cwd' | 'packageManager' | 'exit'>,
	dependencies: PackageInfo[],
	devDependencies: PackageInfo[],
	shellFn: typeof shell = shell,
) {
	const cwd = fileURLToPath(ctx.cwd);
	if (ctx.packageManager.name === 'yarn') await ensureYarnLock({ cwd });

	const installCommand = resolveCommand(ctx.packageManager.agent, 'add', []);
	if (!installCommand) {
		// NOTE: Usually it's impossible to reach here as `package-manager-detector` should
		// already match a supported agent
		error('error', `Unable to find install command for ${ctx.packageManager.name}.`);
		return ctx.exit(1);
	}
	const doInstall = async (legacyPeerDeps = false) => {
		try {
			if (dependencies.length > 0) {
				await shellFn(
					installCommand.command,
					[
						...installCommand.args,
						...(legacyPeerDeps ? ['--legacy-peer-deps'] : []),
						...dependencies.map(
							({ name, targetVersion }) => `${name}@${targetVersion.replace(/^\^/, '')}`,
						),
					],
					{ cwd, timeout: 90_000 },
				);
			}
			if (devDependencies.length > 0) {
				await shellFn(
					installCommand.command,
					[
						...installCommand.args,
						...(legacyPeerDeps ? ['--legacy-peer-deps'] : []),
						...devDependencies.map(
							({ name, targetVersion }) => `${name}@${targetVersion.replace(/^\^/, '')}`,
						),
					],
					{ cwd, timeout: 90_000 },
				);
			}
		} catch (err: unknown) {
			const errorMessage = err instanceof Error ? err.message : String(err);
			// If the error is related to peer dependencies, we can try again with `--legacy-peer-deps`
			if (
				ctx.packageManager.name === 'npm' &&
				!legacyPeerDeps &&
				errorMessage.includes('peer dependenc')
			) {
				return doInstall(true);
			}

			const manualInstallCommand = [
				installCommand.command,
				...installCommand.args,
				...[...dependencies, ...devDependencies].map(
					({ name, targetVersion }) => `${name}@${targetVersion}`,
				),
			].join(' ');
			newline();
			error(
				'error',
				`Dependencies failed to install, please run the following command manually:\n${color.bold(manualInstallCommand)}`,
			);
			return ctx.exit(1);
		}
	};

	await spinner({
		start: `Installing dependencies with ${ctx.packageManager.name}...`,
		end: `Installed dependencies!`,
		while: doInstall,
	});

	await say([`${random(celebrations)} ${random(done)}`, random(bye)], { clear: false });
}

Domain

Subdomains

Called By

Frequently Asked Questions

What does runInstallCommand() do?
runInstallCommand() is a function in the astro codebase, defined in packages/upgrade/src/actions/install.ts.
Where is runInstallCommand() defined?
runInstallCommand() is defined in packages/upgrade/src/actions/install.ts at line 119.
What does runInstallCommand() call?
runInstallCommand() calls 1 function(s): ensureYarnLock.
What calls runInstallCommand()?
runInstallCommand() is called by 1 function(s): install.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free