full site update
This commit is contained in:
8
node_modules/astro/dist/cli/add/index.d.ts
generated
vendored
8
node_modules/astro/dist/cli/add/index.d.ts
generated
vendored
@@ -1,14 +1,6 @@
|
||||
import { type ProxifiedModule } from 'magicast';
|
||||
import { type Flags } from '../flags.js';
|
||||
interface AddOptions {
|
||||
flags: Flags;
|
||||
}
|
||||
interface IntegrationInfo {
|
||||
id: string;
|
||||
packageName: string;
|
||||
dependencies: [name: string, version: string][];
|
||||
type: 'integration' | 'adapter';
|
||||
}
|
||||
export declare function add(names: string[], { flags }: AddOptions): Promise<void>;
|
||||
export declare function setAdapter(mod: ProxifiedModule<any>, adapter: IntegrationInfo, exportName: string): void;
|
||||
export {};
|
||||
|
262
node_modules/astro/dist/cli/add/index.js
generated
vendored
262
node_modules/astro/dist/cli/add/index.js
generated
vendored
@@ -6,10 +6,10 @@ import { diffWords } from "diff";
|
||||
import { bold, cyan, dim, green, magenta, red, yellow } from "kleur/colors";
|
||||
import { builders, generateCode, loadFile } from "magicast";
|
||||
import { getDefaultExportOptions } from "magicast/helpers";
|
||||
import ora from "ora";
|
||||
import preferredPM from "preferred-pm";
|
||||
import { detect, resolveCommand } from "package-manager-detector";
|
||||
import prompts from "prompts";
|
||||
import maxSatisfying from "semver/ranges/max-satisfying.js";
|
||||
import yoctoSpinner from "yocto-spinner";
|
||||
import {
|
||||
loadTSConfig,
|
||||
resolveConfig,
|
||||
@@ -38,15 +38,7 @@ const STUBS = {
|
||||
ASTRO_CONFIG: `import { defineConfig } from 'astro/config';
|
||||
// https://astro.build/config
|
||||
export default defineConfig({});`,
|
||||
TAILWIND_CONFIG: `/** @type {import('tailwindcss').Config} */
|
||||
export default {
|
||||
content: ['./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}'],
|
||||
theme: {
|
||||
extend: {},
|
||||
},
|
||||
plugins: [],
|
||||
}
|
||||
`,
|
||||
TAILWIND_GLOBAL_CSS: `@import "tailwindcss";`,
|
||||
SVELTE_CONFIG: `import { vitePreprocess } from '@astrojs/svelte';
|
||||
|
||||
export default {
|
||||
@@ -73,7 +65,7 @@ export default async function seed() {
|
||||
};
|
||||
const OFFICIAL_ADAPTER_TO_IMPORT_MAP = {
|
||||
netlify: "@astrojs/netlify",
|
||||
vercel: "@astrojs/vercel/serverless",
|
||||
vercel: "@astrojs/vercel",
|
||||
cloudflare: "@astrojs/cloudflare",
|
||||
node: "@astrojs/node"
|
||||
};
|
||||
@@ -125,7 +117,7 @@ async function add(names, { flags }) {
|
||||
const cwd = inlineConfig.root;
|
||||
const logger = createLoggerFromFlags(flags);
|
||||
const integrationNames = names.map((name) => ALIASES.has(name) ? ALIASES.get(name) : name);
|
||||
const integrations = await validateIntegrations(integrationNames);
|
||||
const integrations = await validateIntegrations(integrationNames, flags);
|
||||
let installResult = await tryToInstallIntegrations({ integrations, cwd, flags, logger });
|
||||
const rootPath = resolveRoot(cwd);
|
||||
const root = pathToFileURL(rootPath);
|
||||
@@ -133,22 +125,30 @@ async function add(names, { flags }) {
|
||||
switch (installResult) {
|
||||
case 1 /* updated */: {
|
||||
if (integrations.find((integration) => integration.id === "tailwind")) {
|
||||
await setupIntegrationConfig({
|
||||
root,
|
||||
logger,
|
||||
flags,
|
||||
integrationName: "Tailwind",
|
||||
possibleConfigFiles: [
|
||||
"./tailwind.config.cjs",
|
||||
"./tailwind.config.mjs",
|
||||
"./tailwind.config.ts",
|
||||
"./tailwind.config.mts",
|
||||
"./tailwind.config.cts",
|
||||
"./tailwind.config.js"
|
||||
],
|
||||
defaultConfigFile: "./tailwind.config.mjs",
|
||||
defaultConfigContent: STUBS.TAILWIND_CONFIG
|
||||
});
|
||||
const dir = new URL("./styles/", new URL(userConfig.srcDir ?? "./src/", root));
|
||||
const styles = new URL("./global.css", dir);
|
||||
if (!existsSync(styles)) {
|
||||
logger.info(
|
||||
"SKIP_FORMAT",
|
||||
`
|
||||
${magenta(`Astro will scaffold ${green("./src/styles/global.css")}.`)}
|
||||
`
|
||||
);
|
||||
if (await askToContinue({ flags })) {
|
||||
if (!existsSync(dir)) {
|
||||
await fs.mkdir(dir);
|
||||
}
|
||||
await fs.writeFile(styles, STUBS.TAILWIND_GLOBAL_CSS, "utf-8");
|
||||
} else {
|
||||
logger.info(
|
||||
"SKIP_FORMAT",
|
||||
`
|
||||
@tailwindcss/vite requires additional configuration. Please refer to https://docs.astro.build/en/guides/integrations-guide/tailwind/`
|
||||
);
|
||||
}
|
||||
} else {
|
||||
logger.debug("add", `Using existing tailwind configuration`);
|
||||
}
|
||||
}
|
||||
if (integrations.find((integration) => integration.id === "svelte")) {
|
||||
await setupIntegrationConfig({
|
||||
@@ -190,7 +190,7 @@ async function add(names, { flags }) {
|
||||
logger.debug("add", `Using existing db configuration`);
|
||||
}
|
||||
}
|
||||
if (integrations.find((integration) => integration.id === "lit") && (await preferredPM(fileURLToPath(root)))?.name === "pnpm") {
|
||||
if (integrations.find((integration) => integration.id === "lit") && (await detect({ cwd: fileURLToPath(root) }))?.name === "pnpm") {
|
||||
await setupIntegrationConfig({
|
||||
root,
|
||||
logger,
|
||||
@@ -254,11 +254,13 @@ async function add(names, { flags }) {
|
||||
`
|
||||
${magenta(
|
||||
`Check our deployment docs for ${bold(
|
||||
integration.packageName
|
||||
integration.integrationName
|
||||
)} to update your "adapter" config.`
|
||||
)}`
|
||||
);
|
||||
}
|
||||
} else if (integration.id === "tailwind") {
|
||||
addVitePlugin(mod, "tailwindcss", "@tailwindcss/vite");
|
||||
} else {
|
||||
addIntegration(mod, integration);
|
||||
}
|
||||
@@ -307,10 +309,12 @@ async function add(names, { flags }) {
|
||||
logger.info("SKIP_FORMAT", msg.success(`Configuration up-to-date.`));
|
||||
break;
|
||||
}
|
||||
// NOTE: failure shouldn't happen in practice because `updateAstroConfig` doesn't return that.
|
||||
// Pipe this to the same handling as `UpdateResult.updated` for now.
|
||||
case 3 /* failure */:
|
||||
case 1 /* updated */:
|
||||
case void 0: {
|
||||
const list = integrations.map((integration) => ` - ${integration.packageName}`).join("\n");
|
||||
const list = integrations.map((integration) => ` - ${integration.integrationName}`).join("\n");
|
||||
logger.info(
|
||||
"SKIP_FORMAT",
|
||||
msg.success(
|
||||
@@ -318,6 +322,21 @@ async function add(names, { flags }) {
|
||||
${list}`
|
||||
)
|
||||
);
|
||||
if (integrations.find((integration) => integration.integrationName === "tailwind")) {
|
||||
const code = boxen(getDiffContent("---\n---", "---\nimport '../styles/global.css'\n---"), {
|
||||
margin: 0.5,
|
||||
padding: 0.5,
|
||||
borderStyle: "round",
|
||||
title: "src/layouts/Layout.astro"
|
||||
});
|
||||
logger.warn(
|
||||
"SKIP_FORMAT",
|
||||
msg.actionRequired(
|
||||
"You must import your Tailwind stylesheet, e.g. in a shared layout:\n"
|
||||
)
|
||||
);
|
||||
logger.info("SKIP_FORMAT", code + "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
const updateTSConfigResult = await updateTSConfig(cwd, logger, integrations, flags);
|
||||
@@ -373,6 +392,23 @@ function addIntegration(mod, integration) {
|
||||
config.integrations.push(builders.functionCall(integrationId));
|
||||
}
|
||||
}
|
||||
function addVitePlugin(mod, pluginId, packageName) {
|
||||
const config = getDefaultExportOptions(mod);
|
||||
if (!mod.imports.$items.some((imp) => imp.local === pluginId)) {
|
||||
mod.imports.$append({
|
||||
imported: "default",
|
||||
local: pluginId,
|
||||
from: packageName
|
||||
});
|
||||
}
|
||||
config.vite ??= {};
|
||||
config.vite.plugins ??= [];
|
||||
if (!config.vite.plugins.$ast.elements.some(
|
||||
(el) => el.type === "CallExpression" && el.callee.type === "Identifier" && el.callee.name === pluginId
|
||||
)) {
|
||||
config.vite.plugins.push(builders.functionCall(pluginId));
|
||||
}
|
||||
}
|
||||
function setAdapter(mod, adapter, exportName) {
|
||||
const config = getDefaultExportOptions(mod);
|
||||
const adapterId = toIdent(adapter.id);
|
||||
@@ -383,9 +419,6 @@ function setAdapter(mod, adapter, exportName) {
|
||||
from: exportName
|
||||
});
|
||||
}
|
||||
if (!config.output) {
|
||||
config.output = "server";
|
||||
}
|
||||
switch (adapter.id) {
|
||||
case "node":
|
||||
config.adapter = builders.functionCall(adapterId, { mode: "standalone" });
|
||||
@@ -458,32 +491,9 @@ ${message}`
|
||||
return 2 /* cancelled */;
|
||||
}
|
||||
}
|
||||
async function getInstallIntegrationsCommand({
|
||||
integrations,
|
||||
logger,
|
||||
cwd = process.cwd()
|
||||
}) {
|
||||
const pm = await preferredPM(cwd);
|
||||
logger.debug("add", `package manager: ${JSON.stringify(pm)}`);
|
||||
if (!pm) return null;
|
||||
const dependencies = await convertIntegrationsToInstallSpecifiers(integrations);
|
||||
switch (pm.name) {
|
||||
case "npm":
|
||||
return { pm: "npm", command: "install", flags: [], dependencies };
|
||||
case "yarn":
|
||||
return { pm: "yarn", command: "add", flags: [], dependencies };
|
||||
case "pnpm":
|
||||
return { pm: "pnpm", command: "add", flags: [], dependencies };
|
||||
case "bun":
|
||||
return { pm: "bun", command: "add", flags: [], dependencies };
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
async function convertIntegrationsToInstallSpecifiers(integrations) {
|
||||
const ranges = {};
|
||||
for (let { packageName, dependencies } of integrations) {
|
||||
ranges[packageName] = "*";
|
||||
for (let { dependencies } of integrations) {
|
||||
for (const [name, range] of dependencies) {
|
||||
ranges[name] = range;
|
||||
}
|
||||
@@ -515,7 +525,14 @@ async function tryToInstallIntegrations({
|
||||
flags,
|
||||
logger
|
||||
}) {
|
||||
const installCommand = await getInstallIntegrationsCommand({ integrations, cwd, logger });
|
||||
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"]
|
||||
});
|
||||
logger.debug("add", `package manager: "${packageManager?.name}"`);
|
||||
if (!packageManager) return 0 /* none */;
|
||||
const inheritedFlags = Object.entries(flags).map(([flag]) => {
|
||||
if (flag == "_") return;
|
||||
if (INHERITED_FLAGS.has(flag)) {
|
||||
@@ -523,64 +540,52 @@ async function tryToInstallIntegrations({
|
||||
return `--${flag}`;
|
||||
}
|
||||
}).filter(Boolean).flat();
|
||||
if (installCommand === null) {
|
||||
return 0 /* none */;
|
||||
} else {
|
||||
const coloredOutput = `${bold(installCommand.pm)} ${installCommand.command}${[
|
||||
"",
|
||||
...installCommand.flags,
|
||||
...inheritedFlags
|
||||
].join(" ")} ${cyan(installCommand.dependencies.join(" "))}`;
|
||||
const message = `
|
||||
const installCommand = resolveCommand(packageManager?.agent ?? "npm", "add", inheritedFlags);
|
||||
if (!installCommand) return 0 /* none */;
|
||||
const installSpecifiers = await convertIntegrationsToInstallSpecifiers(integrations).then(
|
||||
(specifiers) => installCommand.command === "deno" ? specifiers.map((specifier) => `npm:${specifier}`) : specifiers
|
||||
);
|
||||
const coloredOutput = `${bold(installCommand.command)} ${installCommand.args.join(" ")} ${cyan(installSpecifiers.join(" "))}`;
|
||||
const message = `
|
||||
${boxen(coloredOutput, {
|
||||
margin: 0.5,
|
||||
padding: 0.5,
|
||||
borderStyle: "round"
|
||||
})}
|
||||
margin: 0.5,
|
||||
padding: 0.5,
|
||||
borderStyle: "round"
|
||||
})}
|
||||
`;
|
||||
logger.info(
|
||||
"SKIP_FORMAT",
|
||||
`
|
||||
logger.info(
|
||||
"SKIP_FORMAT",
|
||||
`
|
||||
${magenta("Astro will run the following command:")}
|
||||
${dim(
|
||||
"If you skip this step, you can always run it yourself later"
|
||||
)}
|
||||
"If you skip this step, you can always run it yourself later"
|
||||
)}
|
||||
${message}`
|
||||
);
|
||||
if (await askToContinue({ flags })) {
|
||||
const spinner = ora("Installing dependencies...").start();
|
||||
try {
|
||||
await exec(
|
||||
installCommand.pm,
|
||||
[
|
||||
installCommand.command,
|
||||
...installCommand.flags,
|
||||
...inheritedFlags,
|
||||
...installCommand.dependencies
|
||||
],
|
||||
{
|
||||
nodeOptions: {
|
||||
cwd,
|
||||
// reset NODE_ENV to ensure install command run in dev mode
|
||||
env: { NODE_ENV: void 0 }
|
||||
}
|
||||
}
|
||||
);
|
||||
spinner.succeed();
|
||||
return 1 /* updated */;
|
||||
} catch (err) {
|
||||
spinner.fail();
|
||||
logger.debug("add", "Error installing dependencies", err);
|
||||
console.error("\n", err.stdout || err.message, "\n");
|
||||
return 3 /* failure */;
|
||||
}
|
||||
} else {
|
||||
return 2 /* cancelled */;
|
||||
);
|
||||
if (await askToContinue({ flags })) {
|
||||
const spinner = yoctoSpinner({ text: "Installing dependencies..." }).start();
|
||||
try {
|
||||
await exec(installCommand.command, [...installCommand.args, ...installSpecifiers], {
|
||||
nodeOptions: {
|
||||
cwd,
|
||||
// reset NODE_ENV to ensure install command run in dev mode
|
||||
env: { NODE_ENV: void 0 }
|
||||
}
|
||||
});
|
||||
spinner.success();
|
||||
return 1 /* updated */;
|
||||
} catch (err) {
|
||||
spinner.error();
|
||||
logger.debug("add", "Error installing dependencies", err);
|
||||
console.error("\n", err.stdout || err.message, "\n");
|
||||
return 3 /* failure */;
|
||||
}
|
||||
} else {
|
||||
return 2 /* cancelled */;
|
||||
}
|
||||
}
|
||||
async function validateIntegrations(integrations) {
|
||||
const spinner = ora("Resolving packages...").start();
|
||||
async function validateIntegrations(integrations, flags) {
|
||||
const spinner = yoctoSpinner({ text: "Resolving packages..." }).start();
|
||||
try {
|
||||
const integrationEntries = await Promise.all(
|
||||
integrations.map(async (integration) => {
|
||||
@@ -597,16 +602,10 @@ async function validateIntegrations(integrations) {
|
||||
const firstPartyPkgCheck = await fetchPackageJson("@astrojs", name, tag);
|
||||
if (firstPartyPkgCheck instanceof Error) {
|
||||
if (firstPartyPkgCheck.message) {
|
||||
spinner.warn(yellow(firstPartyPkgCheck.message));
|
||||
spinner.warning(yellow(firstPartyPkgCheck.message));
|
||||
}
|
||||
spinner.warn(yellow(`${bold(integration)} is not an official Astro package.`));
|
||||
const response = await prompts({
|
||||
type: "confirm",
|
||||
name: "askToContinue",
|
||||
message: "Continue?",
|
||||
initial: true
|
||||
});
|
||||
if (!response.askToContinue) {
|
||||
spinner.warning(yellow(`${bold(integration)} is not an official Astro package.`));
|
||||
if (!await askToContinue({ flags })) {
|
||||
throw new Error(
|
||||
`No problem! Find our official integrations at ${cyan(
|
||||
"https://astro.build/integrations"
|
||||
@@ -624,7 +623,7 @@ async function validateIntegrations(integrations) {
|
||||
const thirdPartyPkgCheck = await fetchPackageJson(scope, name, tag);
|
||||
if (thirdPartyPkgCheck instanceof Error) {
|
||||
if (thirdPartyPkgCheck.message) {
|
||||
spinner.warn(yellow(thirdPartyPkgCheck.message));
|
||||
spinner.warning(yellow(thirdPartyPkgCheck.message));
|
||||
}
|
||||
throw new Error(`Unable to fetch ${bold(integration)}. Does the package exist?`);
|
||||
} else {
|
||||
@@ -633,6 +632,7 @@ async function validateIntegrations(integrations) {
|
||||
}
|
||||
const resolvedScope = pkgType === "first-party" ? "@astrojs" : scope;
|
||||
const packageName = `${resolvedScope ? `${resolvedScope}/` : ""}${name}`;
|
||||
let integrationName = packageName;
|
||||
let dependencies = [
|
||||
[pkgJson["name"], `^${pkgJson["version"]}`]
|
||||
];
|
||||
@@ -661,14 +661,27 @@ async function validateIntegrations(integrations) {
|
||||
)}`
|
||||
);
|
||||
}
|
||||
return { id: integration, packageName, dependencies, type: integrationType };
|
||||
if (integration === "tailwind") {
|
||||
integrationName = "tailwind";
|
||||
dependencies = [
|
||||
["@tailwindcss/vite", "^4.0.0"],
|
||||
["tailwindcss", "^4.0.0"]
|
||||
];
|
||||
}
|
||||
return {
|
||||
id: integration,
|
||||
packageName,
|
||||
dependencies,
|
||||
type: integrationType,
|
||||
integrationName
|
||||
};
|
||||
})
|
||||
);
|
||||
spinner.succeed();
|
||||
spinner.success();
|
||||
return integrationEntries;
|
||||
} catch (e) {
|
||||
if (e instanceof Error) {
|
||||
spinner.fail(e.message);
|
||||
spinner.error(e.message);
|
||||
process.exit(1);
|
||||
} else {
|
||||
throw e;
|
||||
@@ -828,6 +841,5 @@ async function setupIntegrationConfig(opts) {
|
||||
}
|
||||
}
|
||||
export {
|
||||
add,
|
||||
setAdapter
|
||||
add
|
||||
};
|
||||
|
7
node_modules/astro/dist/cli/build/index.js
generated
vendored
7
node_modules/astro/dist/cli/build/index.js
generated
vendored
@@ -9,6 +9,11 @@ async function build({ flags }) {
|
||||
tables: {
|
||||
Flags: [
|
||||
["--outDir <directory>", `Specify the output directory for the build.`],
|
||||
["--mode", `Specify the mode of the project. Defaults to "production".`],
|
||||
[
|
||||
"--devOutput",
|
||||
"Output a development-based build similar to code transformed in `astro dev`."
|
||||
],
|
||||
[
|
||||
"--force",
|
||||
"Clear the content layer and content collection cache, forcing a full rebuild."
|
||||
@@ -21,7 +26,7 @@ async function build({ flags }) {
|
||||
return;
|
||||
}
|
||||
const inlineConfig = flagsToAstroInlineConfig(flags);
|
||||
await _build(inlineConfig);
|
||||
await _build(inlineConfig, { devOutput: !!flags.devOutput });
|
||||
}
|
||||
export {
|
||||
build
|
||||
|
6
node_modules/astro/dist/cli/check/index.js
generated
vendored
6
node_modules/astro/dist/cli/check/index.js
generated
vendored
@@ -25,11 +25,7 @@ async function check(flags) {
|
||||
}
|
||||
if (!flags.noSync && !flags.help) {
|
||||
const { default: sync } = await import("../../core/sync/index.js");
|
||||
try {
|
||||
await sync(flagsToAstroInlineConfig(flags));
|
||||
} catch (_) {
|
||||
return process.exit(1);
|
||||
}
|
||||
await sync(flagsToAstroInlineConfig(flags));
|
||||
}
|
||||
const { check: checker, parseArgsAsCheckConfig } = checkPackage;
|
||||
const config = parseArgsAsCheckConfig(process.argv);
|
||||
|
5
node_modules/astro/dist/cli/dev/index.js
generated
vendored
5
node_modules/astro/dist/cli/dev/index.js
generated
vendored
@@ -9,11 +9,16 @@ async function dev({ flags }) {
|
||||
usage: "[...flags]",
|
||||
tables: {
|
||||
Flags: [
|
||||
["--mode", `Specify the mode of the project. Defaults to "development".`],
|
||||
["--port", `Specify which port to run on. Defaults to 4321.`],
|
||||
["--host", `Listen on all addresses, including LAN and public addresses.`],
|
||||
["--host <custom-address>", `Expose on a network IP address at <custom-address>`],
|
||||
["--open", "Automatically open the app in the browser on server start"],
|
||||
["--force", "Clear the content layer cache, forcing a full rebuild."],
|
||||
[
|
||||
"--allowed-hosts",
|
||||
"Specify a comma-separated list of allowed hosts or allow any hostname."
|
||||
],
|
||||
["--help (-h)", "See all available flags."]
|
||||
]
|
||||
},
|
||||
|
2
node_modules/astro/dist/cli/flags.d.ts
generated
vendored
2
node_modules/astro/dist/cli/flags.d.ts
generated
vendored
@@ -1,6 +1,6 @@
|
||||
import type { Arguments } from 'yargs-parser';
|
||||
import type { AstroInlineConfig } from '../@types/astro.js';
|
||||
import { Logger } from '../core/logger/core.js';
|
||||
import type { AstroInlineConfig } from '../types/public/config.js';
|
||||
export type Flags = Arguments;
|
||||
export declare function flagsToAstroInlineConfig(flags: Flags): AstroInlineConfig;
|
||||
/**
|
||||
|
3
node_modules/astro/dist/cli/flags.js
generated
vendored
3
node_modules/astro/dist/cli/flags.js
generated
vendored
@@ -15,7 +15,8 @@ function flagsToAstroInlineConfig(flags) {
|
||||
server: {
|
||||
port: typeof flags.port === "number" ? flags.port : void 0,
|
||||
host: typeof flags.host === "string" || typeof flags.host === "boolean" ? flags.host : void 0,
|
||||
open: typeof flags.open === "string" || typeof flags.open === "boolean" ? flags.open : void 0
|
||||
open: typeof flags.open === "string" || typeof flags.open === "boolean" ? flags.open : void 0,
|
||||
allowedHosts: typeof flags.allowedHosts === "string" ? flags.allowedHosts.split(",") : typeof flags.allowedHosts === "boolean" && flags.allowedHosts === true ? flags.allowedHosts : []
|
||||
}
|
||||
};
|
||||
}
|
||||
|
3
node_modules/astro/dist/cli/info/index.d.ts
generated
vendored
3
node_modules/astro/dist/cli/info/index.d.ts
generated
vendored
@@ -1,4 +1,4 @@
|
||||
import type { AstroConfig, AstroUserConfig } from '../../@types/astro.js';
|
||||
import type { AstroConfig, AstroUserConfig } from '../../types/public/config.js';
|
||||
import { type Flags } from '../flags.js';
|
||||
interface InfoOptions {
|
||||
flags: Flags;
|
||||
@@ -8,4 +8,5 @@ export declare function getInfoOutput({ userConfig, print, }: {
|
||||
print: boolean;
|
||||
}): Promise<string>;
|
||||
export declare function printInfo({ flags }: InfoOptions): Promise<void>;
|
||||
export declare function readFromClipboard(): string;
|
||||
export {};
|
||||
|
96
node_modules/astro/dist/cli/info/index.js
generated
vendored
96
node_modules/astro/dist/cli/info/index.js
generated
vendored
@@ -1,4 +1,4 @@
|
||||
import { execSync } from "node:child_process";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { arch, platform } from "node:os";
|
||||
import * as colors from "kleur/colors";
|
||||
import prompts from "prompts";
|
||||
@@ -33,48 +33,55 @@ async function printInfo({ flags }) {
|
||||
applyPolyfill();
|
||||
const { userConfig } = await resolveConfig(flagsToAstroInlineConfig(flags), "info");
|
||||
const output = await getInfoOutput({ userConfig, print: true });
|
||||
await copyToClipboard(output);
|
||||
await copyToClipboard(output, flags.copy);
|
||||
}
|
||||
async function copyToClipboard(text) {
|
||||
async function copyToClipboard(text, force) {
|
||||
text = text.trim();
|
||||
const system = platform();
|
||||
let command = "";
|
||||
let args = [];
|
||||
if (system === "darwin") {
|
||||
command = "pbcopy";
|
||||
} else if (system === "win32") {
|
||||
command = "clip";
|
||||
} else {
|
||||
const unixCommands = [
|
||||
["xclip", "-sel clipboard -l 1"],
|
||||
["wl-copy", '"$0"']
|
||||
["xclip", ["-selection", "clipboard", "-l", "1"]],
|
||||
["wl-copy", []]
|
||||
];
|
||||
for (const [unixCommand, args] of unixCommands) {
|
||||
for (const [unixCommand, unixArgs] of unixCommands) {
|
||||
try {
|
||||
const output = execSync(`which ${unixCommand}`, { encoding: "utf8", stdio: "pipe" });
|
||||
if (output[0] !== "/") {
|
||||
continue;
|
||||
const output = spawnSync("which", [unixCommand], { encoding: "utf8" });
|
||||
if (output.stdout.trim()) {
|
||||
command = unixCommand;
|
||||
args = unixArgs;
|
||||
break;
|
||||
}
|
||||
command = `${unixCommand} ${args}`;
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (!command) return;
|
||||
}
|
||||
console.log();
|
||||
const { shouldCopy } = await prompts({
|
||||
type: "confirm",
|
||||
name: "shouldCopy",
|
||||
message: "Copy to clipboard?",
|
||||
initial: true
|
||||
});
|
||||
if (!shouldCopy) return;
|
||||
try {
|
||||
execSync(command.replaceAll("$0", text), {
|
||||
stdio: "ignore",
|
||||
input: text,
|
||||
encoding: "utf8"
|
||||
if (!command) {
|
||||
console.error(colors.red("\nClipboard command not found!"));
|
||||
console.info("Please manually copy the text above.");
|
||||
return;
|
||||
}
|
||||
if (!force) {
|
||||
const { shouldCopy } = await prompts({
|
||||
type: "confirm",
|
||||
name: "shouldCopy",
|
||||
message: "Copy to clipboard?",
|
||||
initial: true
|
||||
});
|
||||
if (!shouldCopy) return;
|
||||
}
|
||||
try {
|
||||
const result = spawnSync(command, args, { input: text, stdio: ["pipe", "ignore", "ignore"] });
|
||||
if (result.error) {
|
||||
throw result.error;
|
||||
}
|
||||
console.info(colors.green("Copied to clipboard!"));
|
||||
} catch {
|
||||
console.error(
|
||||
colors.red(`
|
||||
@@ -82,6 +89,42 @@ Sorry, something went wrong!`) + ` Please copy the text above manually.`
|
||||
);
|
||||
}
|
||||
}
|
||||
function readFromClipboard() {
|
||||
const system = platform();
|
||||
let command = "";
|
||||
let args = [];
|
||||
if (system === "darwin") {
|
||||
command = "pbpaste";
|
||||
} else if (system === "win32") {
|
||||
command = "powershell";
|
||||
args = ["-command", "Get-Clipboard"];
|
||||
} else {
|
||||
const unixCommands = [
|
||||
["xclip", ["-sel", "clipboard", "-o"]],
|
||||
["wl-paste", []]
|
||||
];
|
||||
for (const [unixCommand, unixArgs] of unixCommands) {
|
||||
try {
|
||||
const output = spawnSync("which", [unixCommand], { encoding: "utf8" });
|
||||
if (output.stdout.trim()) {
|
||||
command = unixCommand;
|
||||
args = unixArgs;
|
||||
break;
|
||||
}
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!command) {
|
||||
throw new Error("Clipboard read command not found!");
|
||||
}
|
||||
const result = spawnSync(command, args, { encoding: "utf8" });
|
||||
if (result.error) {
|
||||
throw result.error;
|
||||
}
|
||||
return result.stdout.trim();
|
||||
}
|
||||
const PLATFORM_TO_OS = {
|
||||
darwin: "macOS",
|
||||
win32: "Windows",
|
||||
@@ -115,11 +158,12 @@ ${" ".repeat(MAX_PADDING)}${colors.green(entry)}`;
|
||||
}
|
||||
plaintext += "\n";
|
||||
if (print) {
|
||||
console.log(richtext);
|
||||
console.info(richtext);
|
||||
}
|
||||
return plaintext;
|
||||
}
|
||||
export {
|
||||
getInfoOutput,
|
||||
printInfo
|
||||
printInfo,
|
||||
readFromClipboard
|
||||
};
|
||||
|
6
node_modules/astro/dist/cli/install-package.d.ts
generated
vendored
6
node_modules/astro/dist/cli/install-package.d.ts
generated
vendored
@@ -5,12 +5,6 @@ type GetPackageOptions = {
|
||||
cwd?: string;
|
||||
};
|
||||
export declare function getPackage<T>(packageName: string, logger: Logger, options: GetPackageOptions, otherDeps?: string[]): Promise<T | undefined>;
|
||||
/**
|
||||
* Get the command to execute and download a package (e.g. `npx`, `yarn dlx`, `pnpm dlx`, etc.)
|
||||
* @param packageManager - Optional package manager to use. If not provided, Astro will attempt to detect the preferred package manager.
|
||||
* @returns The command to execute and download a package
|
||||
*/
|
||||
export declare function getExecCommand(packageManager?: string): Promise<string>;
|
||||
export declare function fetchPackageJson(scope: string | undefined, name: string, tag: string): Promise<Record<string, any> | Error>;
|
||||
export declare function fetchPackageVersions(packageName: string): Promise<string[] | Error>;
|
||||
export {};
|
||||
|
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
|
||||
};
|
||||
|
2
node_modules/astro/dist/cli/preferences/index.d.ts
generated
vendored
2
node_modules/astro/dist/cli/preferences/index.d.ts
generated
vendored
@@ -2,7 +2,5 @@ import { type Flags } from '../flags.js';
|
||||
interface PreferencesOptions {
|
||||
flags: Flags;
|
||||
}
|
||||
declare const PREFERENCES_SUBCOMMANDS: readonly ["get", "set", "enable", "disable", "delete", "reset", "list"];
|
||||
export type Subcommand = (typeof PREFERENCES_SUBCOMMANDS)[number];
|
||||
export declare function preferences(subcommand: string, key: string, value: string | undefined, { flags }: PreferencesOptions): Promise<number>;
|
||||
export {};
|
||||
|
2
node_modules/astro/dist/cli/preview/index.d.ts
generated
vendored
2
node_modules/astro/dist/cli/preview/index.d.ts
generated
vendored
@@ -2,5 +2,5 @@ import { type Flags } from '../flags.js';
|
||||
interface PreviewOptions {
|
||||
flags: Flags;
|
||||
}
|
||||
export declare function preview({ flags }: PreviewOptions): Promise<import("../../@types/astro.js").PreviewServer | undefined>;
|
||||
export declare function preview({ flags }: PreviewOptions): Promise<import("../../types/public/preview.js").PreviewServer | undefined>;
|
||||
export {};
|
||||
|
4
node_modules/astro/dist/cli/preview/index.js
generated
vendored
4
node_modules/astro/dist/cli/preview/index.js
generated
vendored
@@ -13,6 +13,10 @@ async function preview({ flags }) {
|
||||
["--host", `Listen on all addresses, including LAN and public addresses.`],
|
||||
["--host <custom-address>", `Expose on a network IP address at <custom-address>`],
|
||||
["--open", "Automatically open the app in the browser on server start"],
|
||||
[
|
||||
"--allowed-hosts",
|
||||
"Specify a comma-separated list of allowed hosts or allow any hostname."
|
||||
],
|
||||
["--help (-h)", "See all available flags."]
|
||||
]
|
||||
},
|
||||
|
4
node_modules/astro/dist/cli/throw-and-exit.js
generated
vendored
4
node_modules/astro/dist/cli/throw-and-exit.js
generated
vendored
@@ -5,7 +5,9 @@ import { debug } from "../core/logger/core.js";
|
||||
import { formatErrorMessage } from "../core/messages.js";
|
||||
import { eventError, telemetry } from "../events/index.js";
|
||||
async function throwAndExit(cmd, err) {
|
||||
if (isAstroConfigZodError(err)) return;
|
||||
if (isAstroConfigZodError(err)) {
|
||||
process.exit(1);
|
||||
}
|
||||
let telemetryPromise;
|
||||
let errorMessage;
|
||||
function exitWithErrorMessage() {
|
||||
|
Reference in New Issue
Block a user