installPackage() — astro Function Reference
Architecture documentation for the installPackage() function in install-package.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD c61261e7_0b4a_22c0_0830_20deeef321f5["installPackage()"] ba36b72c_5f3d_f082_9365_52233650426e["install-package.ts"] c61261e7_0b4a_22c0_0830_20deeef321f5 -->|defined in| ba36b72c_5f3d_f082_9365_52233650426e 9c492abc_d739_31fb_069d_51b959adb806["getPackage()"] 9c492abc_d739_31fb_069d_51b959adb806 -->|calls| c61261e7_0b4a_22c0_0830_20deeef321f5 style c61261e7_0b4a_22c0_0830_20deeef321f5 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/astro/src/cli/install-package.ts lines 59–127
async function installPackage(
packageNames: string[],
options: GetPackageOptions,
logger: Logger,
): Promise<boolean> {
const cwd = options.cwd ?? process.cwd();
const packageManager = await detect({
cwd,
// Include the `install-metadata` strategy to have the package manager that's
// used for installation take precedence
strategies: ['install-metadata', 'lockfile', 'packageManager-field'],
});
const installCommand = resolveCommand(packageManager?.agent ?? 'npm', 'add', []);
if (!installCommand) return false;
if (installCommand.command === 'deno') {
// Deno requires npm prefix to install packages
packageNames = packageNames.map((name) => `npm:${name}`);
}
const coloredOutput = `${bold(installCommand.command)} ${installCommand.args.join(' ')} ${cyan(packageNames.join(' '))}`;
const message = `\n${boxen(coloredOutput, {
margin: 0.5,
padding: 0.5,
borderStyle: 'round',
})}\n`;
logger.info(
'SKIP_FORMAT',
`\n ${magenta('Astro will run the following command:')}\n ${dim(
'If you skip this step, you can always run it yourself later',
)}\n${message}`,
);
let response;
if (options.skipAsk) {
response = true;
} else {
response = (
await prompts({
type: 'confirm',
name: 'askToContinue',
message: 'Continue?',
initial: true,
})
).askToContinue;
}
if (Boolean(response)) {
const spinner = yoctoSpinner({ text: 'Installing dependencies...' }).start();
try {
await exec(installCommand.command, [...installCommand.args, ...packageNames], {
nodeOptions: {
cwd,
// reset NODE_ENV to ensure install command run in dev mode
env: { NODE_ENV: undefined },
},
});
spinner.success();
return true;
} catch (err) {
logger.debug('add', 'Error installing dependencies', err);
spinner.error();
return false;
}
} else {
return false;
}
}
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does installPackage() do?
installPackage() is a function in the astro codebase, defined in packages/astro/src/cli/install-package.ts.
Where is installPackage() defined?
installPackage() is defined in packages/astro/src/cli/install-package.ts at line 59.
What calls installPackage()?
installPackage() is called by 1 function(s): getPackage.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free