full site update
This commit is contained in:
80
node_modules/astro/dist/cli/install-package.js
generated
vendored
80
node_modules/astro/dist/cli/install-package.js
generated
vendored
@@ -2,10 +2,9 @@ import { createRequire } from "node:module";
|
||||
import boxen from "boxen";
|
||||
import ci from "ci-info";
|
||||
import { bold, cyan, dim, magenta } from "kleur/colors";
|
||||
import ora from "ora";
|
||||
import preferredPM from "preferred-pm";
|
||||
import { detect, resolveCommand } from "package-manager-detector";
|
||||
import prompts from "prompts";
|
||||
import whichPm from "which-pm";
|
||||
import yoctoSpinner from "yocto-spinner";
|
||||
import { exec } from "./exec.js";
|
||||
const require2 = createRequire(import.meta.url);
|
||||
async function getPackage(packageName, logger, options, otherDeps = []) {
|
||||
@@ -34,48 +33,20 @@ async function getPackage(packageName, logger, options, otherDeps = []) {
|
||||
}
|
||||
}
|
||||
}
|
||||
function getInstallCommand(packages, packageManager) {
|
||||
switch (packageManager) {
|
||||
case "npm":
|
||||
return { pm: "npm", command: "install", flags: [], dependencies: packages };
|
||||
case "yarn":
|
||||
return { pm: "yarn", command: "add", flags: [], dependencies: packages };
|
||||
case "pnpm":
|
||||
return { pm: "pnpm", command: "add", flags: [], dependencies: packages };
|
||||
case "bun":
|
||||
return { pm: "bun", command: "add", flags: [], dependencies: packages };
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
async function getExecCommand(packageManager) {
|
||||
if (!packageManager) {
|
||||
packageManager = (await preferredPM(process.cwd()))?.name ?? "npm";
|
||||
}
|
||||
switch (packageManager) {
|
||||
case "npm":
|
||||
return "npx";
|
||||
case "yarn":
|
||||
return "yarn dlx";
|
||||
case "pnpm":
|
||||
return "pnpm dlx";
|
||||
case "bun":
|
||||
return "bunx";
|
||||
default:
|
||||
return "npx";
|
||||
}
|
||||
}
|
||||
async function installPackage(packageNames, options, logger) {
|
||||
const cwd = options.cwd ?? process.cwd();
|
||||
const packageManager = (await whichPm(cwd))?.name ?? "npm";
|
||||
const installCommand = getInstallCommand(packageNames, packageManager);
|
||||
if (!installCommand) {
|
||||
return false;
|
||||
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") {
|
||||
packageNames = packageNames.map((name) => `npm:${name}`);
|
||||
}
|
||||
const coloredOutput = `${bold(installCommand.pm)} ${installCommand.command}${[
|
||||
"",
|
||||
...installCommand.flags
|
||||
].join(" ")} ${cyan(installCommand.dependencies.join(" "))}`;
|
||||
const coloredOutput = `${bold(installCommand.command)} ${installCommand.args.join(" ")} ${cyan(packageNames.join(" "))}`;
|
||||
const message = `
|
||||
${boxen(coloredOutput, {
|
||||
margin: 0.5,
|
||||
@@ -104,24 +75,20 @@ ${message}`
|
||||
})).askToContinue;
|
||||
}
|
||||
if (Boolean(response)) {
|
||||
const spinner = ora("Installing dependencies...").start();
|
||||
const spinner = yoctoSpinner({ text: "Installing dependencies..." }).start();
|
||||
try {
|
||||
await exec(
|
||||
installCommand.pm,
|
||||
[installCommand.command, ...installCommand.flags, ...installCommand.dependencies],
|
||||
{
|
||||
nodeOptions: {
|
||||
cwd,
|
||||
// reset NODE_ENV to ensure install command run in dev mode
|
||||
env: { NODE_ENV: void 0 }
|
||||
}
|
||||
await exec(installCommand.command, [...installCommand.args, ...packageNames], {
|
||||
nodeOptions: {
|
||||
cwd,
|
||||
// reset NODE_ENV to ensure install command run in dev mode
|
||||
env: { NODE_ENV: void 0 }
|
||||
}
|
||||
);
|
||||
spinner.succeed();
|
||||
});
|
||||
spinner.success();
|
||||
return true;
|
||||
} catch (err) {
|
||||
logger.debug("add", "Error installing dependencies", err);
|
||||
spinner.fail();
|
||||
spinner.error();
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
@@ -157,7 +124,7 @@ let _registry;
|
||||
async function getRegistry() {
|
||||
if (_registry) return _registry;
|
||||
const fallback = "https://registry.npmjs.org";
|
||||
const packageManager = (await preferredPM(process.cwd()))?.name || "npm";
|
||||
const packageManager = (await detect())?.name || "npm";
|
||||
try {
|
||||
const { stdout } = await exec(packageManager, ["config", "get", "registry"]);
|
||||
_registry = stdout.trim()?.replace(/\/$/, "") || fallback;
|
||||
@@ -170,6 +137,5 @@ async function getRegistry() {
|
||||
export {
|
||||
fetchPackageJson,
|
||||
fetchPackageVersions,
|
||||
getExecCommand,
|
||||
getPackage
|
||||
};
|
||||
|
Reference in New Issue
Block a user