Initial commit
This commit is contained in:
6
node_modules/astro/dist/cli/add/index.d.ts
generated
vendored
Normal file
6
node_modules/astro/dist/cli/add/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import { type Flags } from '../flags.js';
|
||||
interface AddOptions {
|
||||
flags: Flags;
|
||||
}
|
||||
export declare function add(names: string[], { flags }: AddOptions): Promise<void>;
|
||||
export {};
|
||||
967
node_modules/astro/dist/cli/add/index.js
generated
vendored
Normal file
967
node_modules/astro/dist/cli/add/index.js
generated
vendored
Normal file
@@ -0,0 +1,967 @@
|
||||
import fsMod, { existsSync, promises as fs } from "node:fs";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath, pathToFileURL } from "node:url";
|
||||
import boxen from "boxen";
|
||||
import { diffWords } from "diff";
|
||||
import { builders, generateCode, loadFile } from "magicast";
|
||||
import { getDefaultExportOptions } from "magicast/helpers";
|
||||
import { detect, resolveCommand } from "package-manager-detector";
|
||||
import colors from "piccolore";
|
||||
import prompts from "prompts";
|
||||
import maxSatisfying from "semver/ranges/max-satisfying.js";
|
||||
import yoctoSpinner from "yocto-spinner";
|
||||
import {
|
||||
loadTSConfig,
|
||||
resolveConfig,
|
||||
resolveConfigPath,
|
||||
resolveRoot
|
||||
} from "../../core/config/index.js";
|
||||
import {
|
||||
defaultTSConfig,
|
||||
presets,
|
||||
updateTSConfigForFramework
|
||||
} from "../../core/config/tsconfig.js";
|
||||
import * as msg from "../../core/messages.js";
|
||||
import { printHelp } from "../../core/messages.js";
|
||||
import { appendForwardSlash } from "../../core/path.js";
|
||||
import { ensureProcessNodeEnv, parseNpmName } from "../../core/util.js";
|
||||
import { eventCliSession, telemetry } from "../../events/index.js";
|
||||
import { exec } from "../exec.js";
|
||||
import { createLoggerFromFlags, flagsToAstroInlineConfig } from "../flags.js";
|
||||
import { fetchPackageJson, fetchPackageVersions } from "../install-package.js";
|
||||
const { bold, cyan, dim, green, magenta, red, yellow } = colors;
|
||||
const ALIASES = /* @__PURE__ */ new Map([
|
||||
["solid", "solid-js"],
|
||||
["tailwindcss", "tailwind"]
|
||||
]);
|
||||
const STUBS = {
|
||||
ASTRO_CONFIG: `import { defineConfig } from 'astro/config';
|
||||
// https://astro.build/config
|
||||
export default defineConfig({});`,
|
||||
TAILWIND_GLOBAL_CSS: `@import "tailwindcss";`,
|
||||
SVELTE_CONFIG: `import { vitePreprocess } from '@astrojs/svelte';
|
||||
|
||||
export default {
|
||||
preprocess: vitePreprocess(),
|
||||
}
|
||||
`,
|
||||
LIT_NPMRC: `# Lit libraries are required to be hoisted due to dependency issues.
|
||||
public-hoist-pattern[]=*lit*
|
||||
`,
|
||||
DB_CONFIG: `import { defineDb } from 'astro:db';
|
||||
|
||||
// https://astro.build/db/config
|
||||
export default defineDb({
|
||||
tables: {}
|
||||
});
|
||||
`,
|
||||
DB_SEED: `import { db } from 'astro:db';
|
||||
|
||||
// https://astro.build/db/seed
|
||||
export default async function seed() {
|
||||
// TODO
|
||||
}
|
||||
`,
|
||||
CLOUDFLARE_WRANGLER_CONFIG: (name) => `{
|
||||
"main": "dist/_worker.js/index.js",
|
||||
"name": ${JSON.stringify(name)},
|
||||
"compatibility_date": ${JSON.stringify((/* @__PURE__ */ new Date()).toISOString().slice(0, 10))},
|
||||
"compatibility_flags": [
|
||||
"nodejs_compat",
|
||||
"global_fetch_strictly_public"
|
||||
],
|
||||
"assets": {
|
||||
"binding": "ASSETS",
|
||||
"directory": "./dist"
|
||||
},
|
||||
"observability": {
|
||||
"enabled": true
|
||||
}
|
||||
}`,
|
||||
CLOUDFLARE_ASSETSIGNORE: `_worker.js
|
||||
_routes.json`
|
||||
};
|
||||
const OFFICIAL_ADAPTER_TO_IMPORT_MAP = {
|
||||
netlify: "@astrojs/netlify",
|
||||
vercel: "@astrojs/vercel",
|
||||
cloudflare: "@astrojs/cloudflare",
|
||||
node: "@astrojs/node"
|
||||
};
|
||||
async function add(names, { flags }) {
|
||||
ensureProcessNodeEnv("production");
|
||||
const inlineConfig = flagsToAstroInlineConfig(flags);
|
||||
const { userConfig } = await resolveConfig(inlineConfig, "add");
|
||||
telemetry.record(eventCliSession("add", userConfig));
|
||||
if (flags.help || names.length === 0) {
|
||||
printHelp({
|
||||
commandName: "astro add",
|
||||
usage: "[...integrations] [...adapters]",
|
||||
tables: {
|
||||
Flags: [
|
||||
["--yes", "Accept all prompts."],
|
||||
["--help", "Show this help message."]
|
||||
],
|
||||
"UI Frameworks": [
|
||||
["react", "astro add react"],
|
||||
["preact", "astro add preact"],
|
||||
["vue", "astro add vue"],
|
||||
["svelte", "astro add svelte"],
|
||||
["solid-js", "astro add solid-js"],
|
||||
["lit", "astro add lit"],
|
||||
["alpinejs", "astro add alpinejs"]
|
||||
],
|
||||
"Documentation Frameworks": [["starlight", "astro add starlight"]],
|
||||
"SSR Adapters": [
|
||||
["netlify", "astro add netlify"],
|
||||
["vercel", "astro add vercel"],
|
||||
["deno", "astro add deno"],
|
||||
["cloudflare", "astro add cloudflare"],
|
||||
["node", "astro add node"]
|
||||
],
|
||||
Others: [
|
||||
["db", "astro add db"],
|
||||
["tailwind", "astro add tailwind"],
|
||||
["mdx", "astro add mdx"],
|
||||
["markdoc", "astro add markdoc"],
|
||||
["partytown", "astro add partytown"],
|
||||
["sitemap", "astro add sitemap"]
|
||||
]
|
||||
},
|
||||
description: `For more integrations, check out: ${cyan("https://astro.build/integrations")}`
|
||||
});
|
||||
return;
|
||||
}
|
||||
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, flags, logger);
|
||||
let installResult = await tryToInstallIntegrations({ integrations, cwd, flags, logger });
|
||||
const rootPath = resolveRoot(cwd);
|
||||
const root = pathToFileURL(rootPath);
|
||||
root.href = appendForwardSlash(root.href);
|
||||
const rawConfigPath = await resolveConfigPath({
|
||||
root: rootPath,
|
||||
configFile: inlineConfig.configFile,
|
||||
fs: fsMod
|
||||
});
|
||||
let configURL = rawConfigPath ? pathToFileURL(rawConfigPath) : void 0;
|
||||
if (configURL) {
|
||||
logger.debug("add", `Found config at ${configURL}`);
|
||||
} else {
|
||||
logger.info("add", `Unable to locate a config file, generating one for you.`);
|
||||
configURL = new URL("./astro.config.mjs", root);
|
||||
await fs.writeFile(fileURLToPath(configURL), STUBS.ASTRO_CONFIG, { encoding: "utf-8" });
|
||||
}
|
||||
let packageJson = { type: "unknown" };
|
||||
async function getPackageJson() {
|
||||
if (packageJson.type === "exists") {
|
||||
return packageJson.data;
|
||||
}
|
||||
if (packageJson.type === "does-not-exist") {
|
||||
return null;
|
||||
}
|
||||
const pkgURL = new URL("./package.json", configURL);
|
||||
if (existsSync(pkgURL)) {
|
||||
packageJson = {
|
||||
type: "exists",
|
||||
data: await fs.readFile(fileURLToPath(pkgURL)).then((res) => JSON.parse(res.toString()))
|
||||
};
|
||||
return packageJson.data;
|
||||
}
|
||||
packageJson = { type: "does-not-exist" };
|
||||
return null;
|
||||
}
|
||||
switch (installResult) {
|
||||
case 1 /* updated */: {
|
||||
if (integrations.find((integration) => integration.id === "cloudflare")) {
|
||||
const wranglerConfigURL = new URL("./wrangler.jsonc", configURL);
|
||||
if (!existsSync(wranglerConfigURL)) {
|
||||
logger.info(
|
||||
"SKIP_FORMAT",
|
||||
`
|
||||
${magenta(`Astro will scaffold ${green("./wrangler.jsonc")}.`)}
|
||||
`
|
||||
);
|
||||
if (await askToContinue({ flags, logger })) {
|
||||
const data = await getPackageJson();
|
||||
await fs.writeFile(
|
||||
wranglerConfigURL,
|
||||
STUBS.CLOUDFLARE_WRANGLER_CONFIG(data?.name ?? "example"),
|
||||
"utf-8"
|
||||
);
|
||||
}
|
||||
} else {
|
||||
logger.debug("add", "Using existing wrangler configuration");
|
||||
}
|
||||
const dir = new URL(userConfig.publicDir ?? "./public/", root);
|
||||
const assetsignore = new URL("./.assetsignore", dir);
|
||||
if (!existsSync(assetsignore)) {
|
||||
logger.info(
|
||||
"SKIP_FORMAT",
|
||||
`
|
||||
${magenta(`Astro will scaffold ${green("./public/.assetsignore")}.`)}
|
||||
`
|
||||
);
|
||||
if (await askToContinue({ flags, logger })) {
|
||||
if (!existsSync(dir)) {
|
||||
await fs.mkdir(dir);
|
||||
}
|
||||
await fs.writeFile(assetsignore, STUBS.CLOUDFLARE_ASSETSIGNORE, "utf-8");
|
||||
}
|
||||
} else {
|
||||
logger.debug("add", `Using existing .assetsignore`);
|
||||
}
|
||||
}
|
||||
if (integrations.find((integration) => integration.id === "tailwind")) {
|
||||
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, logger })) {
|
||||
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({
|
||||
root,
|
||||
logger,
|
||||
flags,
|
||||
integrationName: "Svelte",
|
||||
possibleConfigFiles: ["./svelte.config.js", "./svelte.config.cjs", "./svelte.config.mjs"],
|
||||
defaultConfigFile: "./svelte.config.js",
|
||||
defaultConfigContent: STUBS.SVELTE_CONFIG
|
||||
});
|
||||
}
|
||||
if (integrations.find((integration) => integration.id === "db")) {
|
||||
if (!existsSync(new URL("./db/", root))) {
|
||||
logger.info(
|
||||
"SKIP_FORMAT",
|
||||
`
|
||||
${magenta(
|
||||
`Astro will scaffold ${green("./db/config.ts")}${magenta(" and ")}${green(
|
||||
"./db/seed.ts"
|
||||
)}${magenta(" files.")}`
|
||||
)}
|
||||
`
|
||||
);
|
||||
if (await askToContinue({ flags, logger })) {
|
||||
await fs.mkdir(new URL("./db", root));
|
||||
await Promise.all([
|
||||
fs.writeFile(new URL("./db/config.ts", root), STUBS.DB_CONFIG, { encoding: "utf-8" }),
|
||||
fs.writeFile(new URL("./db/seed.ts", root), STUBS.DB_SEED, { encoding: "utf-8" })
|
||||
]);
|
||||
} else {
|
||||
logger.info(
|
||||
"SKIP_FORMAT",
|
||||
`
|
||||
Astro DB requires additional configuration. Please refer to https://astro.build/db/config`
|
||||
);
|
||||
}
|
||||
} else {
|
||||
logger.debug("add", `Using existing db configuration`);
|
||||
}
|
||||
}
|
||||
if (integrations.find((integration) => integration.id === "lit") && (await detect({ cwd: fileURLToPath(root) }))?.name === "pnpm") {
|
||||
await setupIntegrationConfig({
|
||||
root,
|
||||
logger,
|
||||
flags,
|
||||
integrationName: "Lit",
|
||||
possibleConfigFiles: ["./.npmrc"],
|
||||
defaultConfigFile: "./.npmrc",
|
||||
defaultConfigContent: STUBS.LIT_NPMRC
|
||||
});
|
||||
}
|
||||
if (integrations.find((integration) => integration.id === "vercel")) {
|
||||
const gitignorePath = new URL("./.gitignore", root);
|
||||
const gitignoreEntry = ".vercel";
|
||||
if (existsSync(gitignorePath)) {
|
||||
const content = await fs.readFile(fileURLToPath(gitignorePath), { encoding: "utf-8" });
|
||||
if (!content.includes(gitignoreEntry)) {
|
||||
logger.info(
|
||||
"SKIP_FORMAT",
|
||||
`
|
||||
${magenta(`Astro will add ${green(".vercel")} to ${green(".gitignore")}.`)}
|
||||
`
|
||||
);
|
||||
if (await askToContinue({ flags, logger })) {
|
||||
const newContent = content.endsWith("\n") ? `${content}${gitignoreEntry}
|
||||
` : `${content}
|
||||
${gitignoreEntry}
|
||||
`;
|
||||
await fs.writeFile(fileURLToPath(gitignorePath), newContent, { encoding: "utf-8" });
|
||||
logger.debug("add", "Updated .gitignore with .vercel");
|
||||
}
|
||||
} else {
|
||||
logger.debug("add", ".vercel already in .gitignore");
|
||||
}
|
||||
} else {
|
||||
logger.info(
|
||||
"SKIP_FORMAT",
|
||||
`
|
||||
${magenta(`Astro will create ${green(".gitignore")} with ${green(".vercel")}.`)}
|
||||
`
|
||||
);
|
||||
if (await askToContinue({ flags, logger })) {
|
||||
await fs.writeFile(fileURLToPath(gitignorePath), `${gitignoreEntry}
|
||||
`, {
|
||||
encoding: "utf-8"
|
||||
});
|
||||
logger.debug("add", "Created .gitignore with .vercel");
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 2 /* cancelled */: {
|
||||
logger.info(
|
||||
"SKIP_FORMAT",
|
||||
msg.cancelled(
|
||||
`Dependencies ${bold("NOT")} installed.`,
|
||||
`Be sure to install them manually before continuing!`
|
||||
)
|
||||
);
|
||||
break;
|
||||
}
|
||||
case 3 /* failure */: {
|
||||
throw createPrettyError(new Error(`Unable to install dependencies`));
|
||||
}
|
||||
case 0 /* none */:
|
||||
break;
|
||||
}
|
||||
let mod;
|
||||
try {
|
||||
mod = await loadFile(fileURLToPath(configURL));
|
||||
logger.debug("add", "Parsed astro config");
|
||||
if (mod.exports.default.$type !== "function-call") {
|
||||
mod.imports.$prepend({ imported: "defineConfig", from: "astro/config" });
|
||||
mod.exports.default = builders.functionCall("defineConfig", mod.exports.default);
|
||||
} else if (mod.exports.default.$args[0] == null) {
|
||||
mod.exports.default.$args[0] = {};
|
||||
}
|
||||
logger.debug("add", "Astro config ensured `defineConfig`");
|
||||
for (const integration of integrations) {
|
||||
if (isAdapter(integration)) {
|
||||
const officialExportName = OFFICIAL_ADAPTER_TO_IMPORT_MAP[integration.id];
|
||||
if (officialExportName) {
|
||||
setAdapter(mod, integration, officialExportName);
|
||||
} else {
|
||||
logger.info(
|
||||
"SKIP_FORMAT",
|
||||
`
|
||||
${magenta(
|
||||
`Check our deployment docs for ${bold(
|
||||
integration.integrationName
|
||||
)} to update your "adapter" config.`
|
||||
)}`
|
||||
);
|
||||
}
|
||||
} else if (integration.id === "tailwind") {
|
||||
addVitePlugin(mod, "tailwindcss", "@tailwindcss/vite");
|
||||
} else {
|
||||
addIntegration(mod, integration);
|
||||
}
|
||||
logger.debug("add", `Astro config added integration ${integration.id}`);
|
||||
}
|
||||
} catch (err) {
|
||||
logger.debug("add", "Error parsing/modifying astro config: ", err);
|
||||
throw createPrettyError(err);
|
||||
}
|
||||
let configResult;
|
||||
if (mod) {
|
||||
try {
|
||||
configResult = await updateAstroConfig({
|
||||
configURL,
|
||||
mod,
|
||||
flags,
|
||||
logger,
|
||||
logAdapterInstructions: integrations.some(isAdapter)
|
||||
});
|
||||
} catch (err) {
|
||||
logger.debug("add", "Error updating astro config", err);
|
||||
throw createPrettyError(err);
|
||||
}
|
||||
}
|
||||
switch (configResult) {
|
||||
case 2 /* cancelled */: {
|
||||
logger.info(
|
||||
"SKIP_FORMAT",
|
||||
msg.cancelled(`Your configuration has ${bold("NOT")} been updated.`)
|
||||
);
|
||||
break;
|
||||
}
|
||||
case 0 /* none */: {
|
||||
const data = await getPackageJson();
|
||||
if (data) {
|
||||
const { dependencies = {}, devDependencies = {} } = data;
|
||||
const deps = Object.keys(Object.assign(dependencies, devDependencies));
|
||||
const missingDeps = integrations.filter(
|
||||
(integration) => !deps.includes(integration.packageName)
|
||||
);
|
||||
if (missingDeps.length === 0) {
|
||||
logger.info("SKIP_FORMAT", msg.success(`Configuration up-to-date.`));
|
||||
break;
|
||||
}
|
||||
}
|
||||
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.integrationName}`).join("\n");
|
||||
logger.info(
|
||||
"SKIP_FORMAT",
|
||||
msg.success(
|
||||
`Added the following integration${integrations.length === 1 ? "" : "s"} to your project:
|
||||
${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);
|
||||
switch (updateTSConfigResult) {
|
||||
case 0 /* none */: {
|
||||
break;
|
||||
}
|
||||
case 2 /* cancelled */: {
|
||||
logger.info(
|
||||
"SKIP_FORMAT",
|
||||
msg.cancelled(`Your TypeScript configuration has ${bold("NOT")} been updated.`)
|
||||
);
|
||||
break;
|
||||
}
|
||||
case 3 /* failure */: {
|
||||
throw new Error(
|
||||
`Unknown error parsing tsconfig.json or jsconfig.json. Could not update TypeScript settings.`
|
||||
);
|
||||
}
|
||||
case 1 /* updated */:
|
||||
logger.info("SKIP_FORMAT", msg.success(`Successfully updated TypeScript settings`));
|
||||
}
|
||||
}
|
||||
function isAdapter(integration) {
|
||||
return integration.type === "adapter";
|
||||
}
|
||||
const toIdent = (name) => {
|
||||
const ident = name.trim().replace(/[-_./]?astro(?:js)?[-_.]?/g, "").replace(/\.js/, "").replace(/[.\-_/]+([a-zA-Z])/g, (_, w) => w.toUpperCase()).replace(/^[^a-zA-Z$_]+/, "").replace(/@.*$/, "");
|
||||
return `${ident[0].toLowerCase()}${ident.slice(1)}`;
|
||||
};
|
||||
function createPrettyError(err) {
|
||||
err.message = `Astro could not update your astro.config.js file safely.
|
||||
Reason: ${err.message}
|
||||
|
||||
You will need to add these integration(s) manually.
|
||||
Documentation: https://docs.astro.build/en/guides/integrations-guide/`;
|
||||
return err;
|
||||
}
|
||||
function addIntegration(mod, integration) {
|
||||
const config = getDefaultExportOptions(mod);
|
||||
const integrationId = toIdent(integration.id);
|
||||
if (!mod.imports.$items.some((imp) => imp.local === integrationId)) {
|
||||
mod.imports.$append({
|
||||
imported: "default",
|
||||
local: integrationId,
|
||||
from: integration.packageName
|
||||
});
|
||||
}
|
||||
config.integrations ??= [];
|
||||
if (!config.integrations.$ast.elements.some(
|
||||
(el) => el.type === "CallExpression" && el.callee.type === "Identifier" && el.callee.name === integrationId
|
||||
)) {
|
||||
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);
|
||||
if (!mod.imports.$items.some((imp) => imp.local === adapterId)) {
|
||||
mod.imports.$append({
|
||||
imported: "default",
|
||||
local: adapterId,
|
||||
from: exportName
|
||||
});
|
||||
}
|
||||
switch (adapter.id) {
|
||||
case "node":
|
||||
config.adapter = builders.functionCall(adapterId, { mode: "standalone" });
|
||||
break;
|
||||
default:
|
||||
config.adapter = builders.functionCall(adapterId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
var UpdateResult = /* @__PURE__ */ ((UpdateResult2) => {
|
||||
UpdateResult2[UpdateResult2["none"] = 0] = "none";
|
||||
UpdateResult2[UpdateResult2["updated"] = 1] = "updated";
|
||||
UpdateResult2[UpdateResult2["cancelled"] = 2] = "cancelled";
|
||||
UpdateResult2[UpdateResult2["failure"] = 3] = "failure";
|
||||
return UpdateResult2;
|
||||
})(UpdateResult || {});
|
||||
async function updateAstroConfig({
|
||||
configURL,
|
||||
mod,
|
||||
flags,
|
||||
logger,
|
||||
logAdapterInstructions
|
||||
}) {
|
||||
const input = await fs.readFile(fileURLToPath(configURL), { encoding: "utf-8" });
|
||||
const output = generateCode(mod, {
|
||||
format: {
|
||||
objectCurlySpacing: true,
|
||||
useTabs: false,
|
||||
tabWidth: 2
|
||||
}
|
||||
}).code;
|
||||
if (input === output) {
|
||||
return 0 /* none */;
|
||||
}
|
||||
const diff = getDiffContent(input, output);
|
||||
if (!diff) {
|
||||
return 0 /* none */;
|
||||
}
|
||||
const message = `
|
||||
${boxen(diff, {
|
||||
margin: 0.5,
|
||||
padding: 0.5,
|
||||
borderStyle: "round",
|
||||
title: configURL.pathname.split("/").pop()
|
||||
})}
|
||||
`;
|
||||
logger.info(
|
||||
"SKIP_FORMAT",
|
||||
`
|
||||
${magenta("Astro will make the following changes to your config file:")}
|
||||
${message}`
|
||||
);
|
||||
if (logAdapterInstructions) {
|
||||
logger.info(
|
||||
"SKIP_FORMAT",
|
||||
magenta(
|
||||
` For complete deployment options, visit
|
||||
${bold(
|
||||
"https://docs.astro.build/en/guides/deploy/"
|
||||
)}
|
||||
`
|
||||
)
|
||||
);
|
||||
}
|
||||
if (await askToContinue({ flags, logger })) {
|
||||
await fs.writeFile(fileURLToPath(configURL), output, { encoding: "utf-8" });
|
||||
logger.debug("add", `Updated astro config`);
|
||||
return 1 /* updated */;
|
||||
} else {
|
||||
return 2 /* cancelled */;
|
||||
}
|
||||
}
|
||||
async function convertIntegrationsToInstallSpecifiers(integrations) {
|
||||
const ranges = {};
|
||||
for (let { dependencies } of integrations) {
|
||||
for (const [name, range] of dependencies) {
|
||||
ranges[name] = range;
|
||||
}
|
||||
}
|
||||
return Promise.all(
|
||||
Object.entries(ranges).map(([name, range]) => resolveRangeToInstallSpecifier(name, range))
|
||||
);
|
||||
}
|
||||
async function resolveRangeToInstallSpecifier(name, range) {
|
||||
const versions = await fetchPackageVersions(name);
|
||||
if (versions instanceof Error) return name;
|
||||
const stableVersions = versions.filter((v) => !v.includes("-"));
|
||||
const maxStable = maxSatisfying(stableVersions, range) ?? maxSatisfying(versions, range);
|
||||
if (!maxStable) return name;
|
||||
return `${name}@^${maxStable}`;
|
||||
}
|
||||
const INHERITED_FLAGS = /* @__PURE__ */ new Set([
|
||||
"P",
|
||||
"save-prod",
|
||||
"D",
|
||||
"save-dev",
|
||||
"E",
|
||||
"save-exact",
|
||||
"no-save"
|
||||
]);
|
||||
async function tryToInstallIntegrations({
|
||||
integrations,
|
||||
cwd,
|
||||
flags,
|
||||
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)) {
|
||||
if (flag.length === 1) return `-${flag}`;
|
||||
return `--${flag}`;
|
||||
}
|
||||
}).filter(Boolean).flat();
|
||||
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"
|
||||
})}
|
||||
`;
|
||||
logger.info(
|
||||
"SKIP_FORMAT",
|
||||
`
|
||||
${magenta("Astro will run the following command:")}
|
||||
${dim(
|
||||
"If you skip this step, you can always run it yourself later"
|
||||
)}
|
||||
${message}`
|
||||
);
|
||||
if (await askToContinue({ flags, logger })) {
|
||||
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, flags, logger) {
|
||||
const spinner = yoctoSpinner({ text: "Resolving packages..." }).start();
|
||||
try {
|
||||
const integrationEntries = await Promise.all(
|
||||
integrations.map(async (integration) => {
|
||||
const parsed = parseIntegrationName(integration);
|
||||
if (!parsed) {
|
||||
throw new Error(`${bold(integration)} does not appear to be a valid package name!`);
|
||||
}
|
||||
let { scope, name, tag } = parsed;
|
||||
let pkgJson;
|
||||
let pkgType;
|
||||
if (scope && scope !== "@astrojs") {
|
||||
pkgType = "third-party";
|
||||
} else {
|
||||
const firstPartyPkgCheck = await fetchPackageJson("@astrojs", name, tag);
|
||||
if (firstPartyPkgCheck instanceof Error) {
|
||||
if (firstPartyPkgCheck.message) {
|
||||
spinner.warning(yellow(firstPartyPkgCheck.message));
|
||||
}
|
||||
spinner.warning(yellow(`${bold(integration)} is not an official Astro package.`));
|
||||
if (!await askToContinue({ flags, logger })) {
|
||||
throw new Error(
|
||||
`No problem! Find our official integrations at ${cyan(
|
||||
"https://astro.build/integrations"
|
||||
)}`
|
||||
);
|
||||
}
|
||||
spinner.start("Resolving with third party packages...");
|
||||
pkgType = "third-party";
|
||||
} else {
|
||||
pkgType = "first-party";
|
||||
pkgJson = firstPartyPkgCheck;
|
||||
}
|
||||
}
|
||||
if (pkgType === "third-party") {
|
||||
const thirdPartyPkgCheck = await fetchPackageJson(scope, name, tag);
|
||||
if (thirdPartyPkgCheck instanceof Error) {
|
||||
if (thirdPartyPkgCheck.message) {
|
||||
spinner.warning(yellow(thirdPartyPkgCheck.message));
|
||||
}
|
||||
throw new Error(`Unable to fetch ${bold(integration)}. Does the package exist?`);
|
||||
} else {
|
||||
pkgJson = thirdPartyPkgCheck;
|
||||
}
|
||||
}
|
||||
const resolvedScope = pkgType === "first-party" ? "@astrojs" : scope;
|
||||
const packageName = `${resolvedScope ? `${resolvedScope}/` : ""}${name}`;
|
||||
let integrationName = packageName;
|
||||
let dependencies = [
|
||||
[pkgJson["name"], `^${pkgJson["version"]}`]
|
||||
];
|
||||
if (pkgJson["peerDependencies"]) {
|
||||
const meta = pkgJson["peerDependenciesMeta"] || {};
|
||||
for (const peer in pkgJson["peerDependencies"]) {
|
||||
const optional = meta[peer]?.optional || false;
|
||||
const isAstro = peer === "astro";
|
||||
if (!optional && !isAstro) {
|
||||
dependencies.push([peer, pkgJson["peerDependencies"][peer]]);
|
||||
}
|
||||
}
|
||||
}
|
||||
let integrationType;
|
||||
const keywords = Array.isArray(pkgJson["keywords"]) ? pkgJson["keywords"] : [];
|
||||
if (keywords.includes("astro-integration")) {
|
||||
integrationType = "integration";
|
||||
} else if (keywords.includes("astro-adapter")) {
|
||||
integrationType = "adapter";
|
||||
} else {
|
||||
throw new Error(
|
||||
`${bold(
|
||||
packageName
|
||||
)} doesn't appear to be an integration or an adapter. Find our official integrations at ${cyan(
|
||||
"https://astro.build/integrations"
|
||||
)}`
|
||||
);
|
||||
}
|
||||
if (integration === "tailwind") {
|
||||
integrationName = "tailwind";
|
||||
dependencies = [
|
||||
["@tailwindcss/vite", "^4.0.0"],
|
||||
["tailwindcss", "^4.0.0"]
|
||||
];
|
||||
}
|
||||
return {
|
||||
id: integration,
|
||||
packageName,
|
||||
dependencies,
|
||||
type: integrationType,
|
||||
integrationName
|
||||
};
|
||||
})
|
||||
);
|
||||
spinner.success();
|
||||
return integrationEntries;
|
||||
} catch (e) {
|
||||
if (e instanceof Error) {
|
||||
spinner.error(e.message);
|
||||
process.exit(1);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
async function updateTSConfig(cwd = process.cwd(), logger, integrationsInfo, flags) {
|
||||
const integrations = integrationsInfo.map(
|
||||
(integration) => integration.id
|
||||
);
|
||||
const firstIntegrationWithTSSettings = integrations.find(
|
||||
(integration) => presets.has(integration)
|
||||
);
|
||||
if (!firstIntegrationWithTSSettings) {
|
||||
return 0 /* none */;
|
||||
}
|
||||
let inputConfig = await loadTSConfig(cwd);
|
||||
let inputConfigText = "";
|
||||
if (inputConfig === "invalid-config" || inputConfig === "unknown-error") {
|
||||
return 3 /* failure */;
|
||||
} else if (inputConfig === "missing-config") {
|
||||
logger.debug("add", "Couldn't find tsconfig.json or jsconfig.json, generating one");
|
||||
inputConfig = {
|
||||
tsconfig: defaultTSConfig,
|
||||
tsconfigFile: path.join(cwd, "tsconfig.json"),
|
||||
rawConfig: defaultTSConfig
|
||||
};
|
||||
} else {
|
||||
inputConfigText = JSON.stringify(inputConfig.rawConfig, null, 2);
|
||||
}
|
||||
const configFileName = path.basename(inputConfig.tsconfigFile);
|
||||
const outputConfig = updateTSConfigForFramework(
|
||||
inputConfig.rawConfig,
|
||||
firstIntegrationWithTSSettings
|
||||
);
|
||||
const output = JSON.stringify(outputConfig, null, 2);
|
||||
const diff = getDiffContent(inputConfigText, output);
|
||||
if (!diff) {
|
||||
return 0 /* none */;
|
||||
}
|
||||
const message = `
|
||||
${boxen(diff, {
|
||||
margin: 0.5,
|
||||
padding: 0.5,
|
||||
borderStyle: "round",
|
||||
title: configFileName
|
||||
})}
|
||||
`;
|
||||
logger.info(
|
||||
"SKIP_FORMAT",
|
||||
`
|
||||
${magenta(`Astro will make the following changes to your ${configFileName}:`)}
|
||||
${message}`
|
||||
);
|
||||
const conflictingIntegrations = [...Object.keys(presets).filter((config) => config !== "vue")];
|
||||
const hasConflictingIntegrations = integrations.filter((integration) => presets.has(integration)).length > 1 && integrations.filter((integration) => conflictingIntegrations.includes(integration)).length > 0;
|
||||
if (hasConflictingIntegrations) {
|
||||
logger.info(
|
||||
"SKIP_FORMAT",
|
||||
red(
|
||||
` ${bold(
|
||||
"Caution:"
|
||||
)} Selected UI frameworks require conflicting tsconfig.json settings, as such only settings for ${bold(
|
||||
firstIntegrationWithTSSettings
|
||||
)} were used.
|
||||
More information: https://docs.astro.build/en/guides/typescript/#errors-typing-multiple-jsx-frameworks-at-the-same-time
|
||||
`
|
||||
)
|
||||
);
|
||||
}
|
||||
if (await askToContinue({ flags, logger })) {
|
||||
await fs.writeFile(inputConfig.tsconfigFile, output, {
|
||||
encoding: "utf-8"
|
||||
});
|
||||
logger.debug("add", `Updated ${configFileName} file`);
|
||||
return 1 /* updated */;
|
||||
} else {
|
||||
return 2 /* cancelled */;
|
||||
}
|
||||
}
|
||||
function parseIntegrationName(spec) {
|
||||
const result = parseNpmName(spec);
|
||||
if (!result) return;
|
||||
let { scope, name } = result;
|
||||
let tag = "latest";
|
||||
if (scope) {
|
||||
name = name.replace(scope + "/", "");
|
||||
}
|
||||
if (name.includes("@")) {
|
||||
const tagged = name.split("@");
|
||||
name = tagged[0];
|
||||
tag = tagged[1];
|
||||
}
|
||||
return { scope, name, tag };
|
||||
}
|
||||
let hasHintedAboutYesFlag = false;
|
||||
async function askToContinue({
|
||||
flags,
|
||||
logger
|
||||
}) {
|
||||
if (flags.yes || flags.y) return true;
|
||||
if (!hasHintedAboutYesFlag) {
|
||||
hasHintedAboutYesFlag = true;
|
||||
logger.info("SKIP_FORMAT", dim(" To run this command without prompts, pass the --yes flag\n"));
|
||||
}
|
||||
const response = await prompts({
|
||||
type: "confirm",
|
||||
name: "askToContinue",
|
||||
message: "Continue?",
|
||||
initial: true
|
||||
});
|
||||
return Boolean(response.askToContinue);
|
||||
}
|
||||
function getDiffContent(input, output) {
|
||||
let changes = [];
|
||||
for (const change of diffWords(input, output)) {
|
||||
let lines = change.value.trim().split("\n").slice(0, change.count);
|
||||
if (lines.length === 0) continue;
|
||||
if (change.added) {
|
||||
if (!change.value.trim()) continue;
|
||||
changes.push(change.value);
|
||||
}
|
||||
}
|
||||
if (changes.length === 0) {
|
||||
return null;
|
||||
}
|
||||
let diffed = output;
|
||||
for (let newContent of changes) {
|
||||
const coloredOutput = newContent.split("\n").map((ln) => ln ? green(ln) : "").join("\n");
|
||||
diffed = diffed.replace(newContent, coloredOutput);
|
||||
}
|
||||
return diffed;
|
||||
}
|
||||
async function setupIntegrationConfig(opts) {
|
||||
const logger = opts.logger;
|
||||
const possibleConfigFiles = opts.possibleConfigFiles.map(
|
||||
(p) => fileURLToPath(new URL(p, opts.root))
|
||||
);
|
||||
let alreadyConfigured = false;
|
||||
for (const possibleConfigPath of possibleConfigFiles) {
|
||||
if (existsSync(possibleConfigPath)) {
|
||||
alreadyConfigured = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!alreadyConfigured) {
|
||||
logger.info(
|
||||
"SKIP_FORMAT",
|
||||
`
|
||||
${magenta(`Astro will generate a minimal ${bold(opts.defaultConfigFile)} file.`)}
|
||||
`
|
||||
);
|
||||
if (await askToContinue({ flags: opts.flags, logger })) {
|
||||
await fs.writeFile(
|
||||
fileURLToPath(new URL(opts.defaultConfigFile, opts.root)),
|
||||
opts.defaultConfigContent,
|
||||
{
|
||||
encoding: "utf-8"
|
||||
}
|
||||
);
|
||||
logger.debug("add", `Generated default ${opts.defaultConfigFile} file`);
|
||||
}
|
||||
} else {
|
||||
logger.debug("add", `Using existing ${opts.integrationName} configuration`);
|
||||
}
|
||||
}
|
||||
export {
|
||||
add
|
||||
};
|
||||
6
node_modules/astro/dist/cli/build/index.d.ts
generated
vendored
Normal file
6
node_modules/astro/dist/cli/build/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import { type Flags } from '../flags.js';
|
||||
interface BuildOptions {
|
||||
flags: Flags;
|
||||
}
|
||||
export declare function build({ flags }: BuildOptions): Promise<void>;
|
||||
export {};
|
||||
33
node_modules/astro/dist/cli/build/index.js
generated
vendored
Normal file
33
node_modules/astro/dist/cli/build/index.js
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
import _build from "../../core/build/index.js";
|
||||
import { printHelp } from "../../core/messages.js";
|
||||
import { flagsToAstroInlineConfig } from "../flags.js";
|
||||
async function build({ flags }) {
|
||||
if (flags?.help || flags?.h) {
|
||||
printHelp({
|
||||
commandName: "astro build",
|
||||
usage: "[...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."
|
||||
],
|
||||
["--help (-h)", "See all available flags."]
|
||||
]
|
||||
},
|
||||
description: `Builds your site for deployment.`
|
||||
});
|
||||
return;
|
||||
}
|
||||
const inlineConfig = flagsToAstroInlineConfig(flags);
|
||||
await _build(inlineConfig, { devOutput: !!flags.devOutput });
|
||||
}
|
||||
export {
|
||||
build
|
||||
};
|
||||
2
node_modules/astro/dist/cli/check/index.d.ts
generated
vendored
Normal file
2
node_modules/astro/dist/cli/check/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { type Flags } from '../flags.js';
|
||||
export declare function check(flags: Flags): Promise<boolean | void>;
|
||||
37
node_modules/astro/dist/cli/check/index.js
generated
vendored
Normal file
37
node_modules/astro/dist/cli/check/index.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
import path from "node:path";
|
||||
import { ensureProcessNodeEnv } from "../../core/util.js";
|
||||
import { createLoggerFromFlags, flagsToAstroInlineConfig } from "../flags.js";
|
||||
import { getPackage } from "../install-package.js";
|
||||
async function check(flags) {
|
||||
ensureProcessNodeEnv("production");
|
||||
const logger = createLoggerFromFlags(flags);
|
||||
const getPackageOpts = {
|
||||
skipAsk: !!flags.yes || !!flags.y,
|
||||
cwd: flags.root
|
||||
};
|
||||
const checkPackage = await getPackage(
|
||||
"@astrojs/check",
|
||||
logger,
|
||||
getPackageOpts,
|
||||
["typescript"]
|
||||
);
|
||||
const typescript = await getPackage("typescript", logger, getPackageOpts);
|
||||
if (!checkPackage || !typescript) {
|
||||
logger.error(
|
||||
"check",
|
||||
"The `@astrojs/check` and `typescript` packages are required for this command to work. Please manually install them into your project and try again."
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (!flags.noSync && !flags.help) {
|
||||
const { default: sync } = await import("../../core/sync/index.js");
|
||||
await sync(flagsToAstroInlineConfig(flags));
|
||||
}
|
||||
const { check: checker, parseArgsAsCheckConfig } = checkPackage;
|
||||
const config = parseArgsAsCheckConfig(process.argv);
|
||||
logger.info("check", `Getting diagnostics for Astro files in ${path.resolve(config.root)}...`);
|
||||
return await checker(config);
|
||||
}
|
||||
export {
|
||||
check
|
||||
};
|
||||
17
node_modules/astro/dist/cli/create-key/core/create-key.d.ts
generated
vendored
Normal file
17
node_modules/astro/dist/cli/create-key/core/create-key.d.ts
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
import type { Logger } from '../../../core/logger/core.js';
|
||||
import type { KeyGenerator } from '../definitions.js';
|
||||
interface Options {
|
||||
logger: Logger;
|
||||
keyGenerator: KeyGenerator;
|
||||
}
|
||||
export declare const createKeyCommand: {
|
||||
help: {
|
||||
commandName: string;
|
||||
tables: {
|
||||
Flags: [string, string][];
|
||||
};
|
||||
description: string;
|
||||
};
|
||||
run({ logger, keyGenerator }: Options): Promise<void>;
|
||||
};
|
||||
export {};
|
||||
22
node_modules/astro/dist/cli/create-key/core/create-key.js
generated
vendored
Normal file
22
node_modules/astro/dist/cli/create-key/core/create-key.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
import { defineCommand } from "../../domain/command.js";
|
||||
const createKeyCommand = defineCommand({
|
||||
help: {
|
||||
commandName: "astro create-key",
|
||||
tables: {
|
||||
Flags: [["--help (-h)", "See all available flags."]]
|
||||
},
|
||||
description: "Generates a key to encrypt props passed to server islands."
|
||||
},
|
||||
async run({ logger, keyGenerator }) {
|
||||
const key = await keyGenerator.generate();
|
||||
logger.info(
|
||||
"crypto",
|
||||
`Generated a key to encrypt props passed to server islands. To reuse the same key across builds, set this value as ASTRO_KEY in an environment variable on your build server.
|
||||
|
||||
ASTRO_KEY=${key}`
|
||||
);
|
||||
}
|
||||
});
|
||||
export {
|
||||
createKeyCommand
|
||||
};
|
||||
3
node_modules/astro/dist/cli/create-key/definitions.d.ts
generated
vendored
Normal file
3
node_modules/astro/dist/cli/create-key/definitions.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export interface KeyGenerator {
|
||||
generate: () => Promise<string>;
|
||||
}
|
||||
0
node_modules/astro/dist/cli/create-key/definitions.js
generated
vendored
Normal file
0
node_modules/astro/dist/cli/create-key/definitions.js
generated
vendored
Normal file
4
node_modules/astro/dist/cli/create-key/infra/crypto-key-generator.d.ts
generated
vendored
Normal file
4
node_modules/astro/dist/cli/create-key/infra/crypto-key-generator.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import type { KeyGenerator } from '../definitions.js';
|
||||
export declare class CryptoKeyGenerator implements KeyGenerator {
|
||||
generate(): Promise<string>;
|
||||
}
|
||||
11
node_modules/astro/dist/cli/create-key/infra/crypto-key-generator.js
generated
vendored
Normal file
11
node_modules/astro/dist/cli/create-key/infra/crypto-key-generator.js
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
import { createKey, encodeKey } from "../../../core/encryption.js";
|
||||
class CryptoKeyGenerator {
|
||||
async generate() {
|
||||
const key = await createKey();
|
||||
const encoded = await encodeKey(key);
|
||||
return encoded;
|
||||
}
|
||||
}
|
||||
export {
|
||||
CryptoKeyGenerator
|
||||
};
|
||||
4
node_modules/astro/dist/cli/db/index.d.ts
generated
vendored
Normal file
4
node_modules/astro/dist/cli/db/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import type { Arguments } from 'yargs-parser';
|
||||
export declare function db({ flags }: {
|
||||
flags: Arguments;
|
||||
}): Promise<void>;
|
||||
25
node_modules/astro/dist/cli/db/index.js
generated
vendored
Normal file
25
node_modules/astro/dist/cli/db/index.js
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
import { resolveConfig } from "../../core/config/config.js";
|
||||
import { createLoggerFromFlags, flagsToAstroInlineConfig } from "../flags.js";
|
||||
import { getPackage } from "../install-package.js";
|
||||
async function db({ flags }) {
|
||||
const logger = createLoggerFromFlags(flags);
|
||||
const getPackageOpts = {
|
||||
skipAsk: !!flags.yes || !!flags.y,
|
||||
cwd: flags.root
|
||||
};
|
||||
const dbPackage = await getPackage("@astrojs/db", logger, getPackageOpts, []);
|
||||
if (!dbPackage) {
|
||||
logger.error(
|
||||
"check",
|
||||
"The `@astrojs/db` package is required for this command to work. Please manually install it in your project and try again."
|
||||
);
|
||||
return;
|
||||
}
|
||||
const { cli } = dbPackage;
|
||||
const inlineConfig = flagsToAstroInlineConfig(flags);
|
||||
const { astroConfig } = await resolveConfig(inlineConfig, "build");
|
||||
await cli({ flags, config: astroConfig });
|
||||
}
|
||||
export {
|
||||
db
|
||||
};
|
||||
37
node_modules/astro/dist/cli/definitions.d.ts
generated
vendored
Normal file
37
node_modules/astro/dist/cli/definitions.d.ts
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
import type { StdioOptions } from 'node:child_process';
|
||||
import type { AnyCommand } from './domain/command.js';
|
||||
import type { HelpPayload } from './domain/help-payload.js';
|
||||
export interface HelpDisplay {
|
||||
shouldFire: () => boolean;
|
||||
show: (payload: HelpPayload) => void;
|
||||
}
|
||||
export interface TextStyler {
|
||||
bgWhite: (msg: string) => string;
|
||||
black: (msg: string) => string;
|
||||
dim: (msg: string) => string;
|
||||
green: (msg: string) => string;
|
||||
bold: (msg: string) => string;
|
||||
bgGreen: (msg: string) => string;
|
||||
}
|
||||
export interface AstroVersionProvider {
|
||||
readonly version: string;
|
||||
}
|
||||
export interface CommandRunner {
|
||||
run: <T extends AnyCommand>(command: T, ...args: Parameters<T['run']>) => ReturnType<T['run']> | undefined;
|
||||
}
|
||||
export interface CommandExecutorOptions {
|
||||
cwd?: string;
|
||||
env?: Record<string, string | undefined>;
|
||||
shell?: boolean;
|
||||
input?: string;
|
||||
stdio?: StdioOptions;
|
||||
}
|
||||
export interface CommandExecutor {
|
||||
execute: (command: string, args?: Array<string>, options?: CommandExecutorOptions) => Promise<{
|
||||
stdout: string;
|
||||
}>;
|
||||
}
|
||||
export interface OperatingSystemProvider {
|
||||
readonly name: NodeJS.Platform;
|
||||
readonly displayName: string;
|
||||
}
|
||||
0
node_modules/astro/dist/cli/definitions.js
generated
vendored
Normal file
0
node_modules/astro/dist/cli/definitions.js
generated
vendored
Normal file
6
node_modules/astro/dist/cli/dev/index.d.ts
generated
vendored
Normal file
6
node_modules/astro/dist/cli/dev/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import { type Flags } from '../flags.js';
|
||||
interface DevOptions {
|
||||
flags: Flags;
|
||||
}
|
||||
export declare function dev({ flags }: DevOptions): Promise<import("../../core/dev/dev.js").DevServer | undefined>;
|
||||
export {};
|
||||
36
node_modules/astro/dist/cli/dev/index.js
generated
vendored
Normal file
36
node_modules/astro/dist/cli/dev/index.js
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
import colors from "piccolore";
|
||||
import devServer from "../../core/dev/index.js";
|
||||
import { printHelp } from "../../core/messages.js";
|
||||
import { flagsToAstroInlineConfig } from "../flags.js";
|
||||
async function dev({ flags }) {
|
||||
if (flags.help || flags.h) {
|
||||
printHelp({
|
||||
commandName: "astro dev",
|
||||
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."]
|
||||
]
|
||||
},
|
||||
description: `Check ${colors.cyan(
|
||||
"https://docs.astro.build/en/reference/cli-reference/#astro-dev"
|
||||
)} for more information.`
|
||||
});
|
||||
return;
|
||||
}
|
||||
const inlineConfig = flagsToAstroInlineConfig(flags);
|
||||
return await devServer(inlineConfig);
|
||||
}
|
||||
export {
|
||||
dev
|
||||
};
|
||||
21
node_modules/astro/dist/cli/docs/core/open-docs.d.ts
generated
vendored
Normal file
21
node_modules/astro/dist/cli/docs/core/open-docs.d.ts
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
import type { Logger } from '../../../core/logger/core.js';
|
||||
import type { CommandExecutor, OperatingSystemProvider } from '../../definitions.js';
|
||||
import type { CloudIdeProvider } from '../definitions.js';
|
||||
interface Options {
|
||||
url: string;
|
||||
operatingSystemProvider: OperatingSystemProvider;
|
||||
logger: Logger;
|
||||
commandExecutor: CommandExecutor;
|
||||
cloudIdeProvider: CloudIdeProvider;
|
||||
}
|
||||
export declare const openDocsCommand: {
|
||||
help: {
|
||||
commandName: string;
|
||||
tables: {
|
||||
Flags: [string, string][];
|
||||
};
|
||||
description: string;
|
||||
};
|
||||
run({ url, operatingSystemProvider, logger, commandExecutor, cloudIdeProvider }: Options): Promise<void>;
|
||||
};
|
||||
export {};
|
||||
42
node_modules/astro/dist/cli/docs/core/open-docs.js
generated
vendored
Normal file
42
node_modules/astro/dist/cli/docs/core/open-docs.js
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
import { defineCommand } from "../../domain/command.js";
|
||||
function getExecInputForPlatform(platform) {
|
||||
switch (platform) {
|
||||
case "android":
|
||||
case "linux":
|
||||
return ["xdg-open"];
|
||||
case "darwin":
|
||||
return ["open"];
|
||||
case "win32":
|
||||
return ["cmd", ["/c", "start"]];
|
||||
case "gitpod":
|
||||
return ["/ide/bin/remote-cli/gitpod-code", ["--openExternal"]];
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
const openDocsCommand = defineCommand({
|
||||
help: {
|
||||
commandName: "astro docs",
|
||||
tables: {
|
||||
Flags: [["--help (-h)", "See all available flags."]]
|
||||
},
|
||||
description: `Launches the Astro Docs website directly from the terminal.`
|
||||
},
|
||||
async run({ url, operatingSystemProvider, logger, commandExecutor, cloudIdeProvider }) {
|
||||
const platform = cloudIdeProvider.name ?? operatingSystemProvider.name;
|
||||
const input = getExecInputForPlatform(platform);
|
||||
if (!input) {
|
||||
logger.error(
|
||||
"SKIP_FORMAT",
|
||||
`It looks like your platform ("${platform}") isn't supported!
|
||||
To view Astro's docs, please visit ${url}`
|
||||
);
|
||||
return;
|
||||
}
|
||||
const [command, args = []] = input;
|
||||
await commandExecutor.execute(command, [...args, encodeURI(url)]);
|
||||
}
|
||||
});
|
||||
export {
|
||||
openDocsCommand
|
||||
};
|
||||
4
node_modules/astro/dist/cli/docs/definitions.d.ts
generated
vendored
Normal file
4
node_modules/astro/dist/cli/docs/definitions.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import type { CloudIde } from './domain/cloud-ide.js';
|
||||
export interface CloudIdeProvider {
|
||||
readonly name: CloudIde | null;
|
||||
}
|
||||
0
node_modules/astro/dist/cli/docs/definitions.js
generated
vendored
Normal file
0
node_modules/astro/dist/cli/docs/definitions.js
generated
vendored
Normal file
1
node_modules/astro/dist/cli/docs/domain/cloud-ide.d.ts
generated
vendored
Normal file
1
node_modules/astro/dist/cli/docs/domain/cloud-ide.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export type CloudIde = 'gitpod';
|
||||
0
node_modules/astro/dist/cli/docs/domain/cloud-ide.js
generated
vendored
Normal file
0
node_modules/astro/dist/cli/docs/domain/cloud-ide.js
generated
vendored
Normal file
5
node_modules/astro/dist/cli/docs/infra/process-cloud-ide-provider.d.ts
generated
vendored
Normal file
5
node_modules/astro/dist/cli/docs/infra/process-cloud-ide-provider.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import type { CloudIdeProvider } from '../definitions.js';
|
||||
import type { CloudIde } from '../domain/cloud-ide.js';
|
||||
export declare class ProcessCloudIdeProvider implements CloudIdeProvider {
|
||||
readonly name: CloudIde | null;
|
||||
}
|
||||
6
node_modules/astro/dist/cli/docs/infra/process-cloud-ide-provider.js
generated
vendored
Normal file
6
node_modules/astro/dist/cli/docs/infra/process-cloud-ide-provider.js
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
class ProcessCloudIdeProvider {
|
||||
name = Boolean(process.env.GITPOD_REPO_ROOT) ? "gitpod" : null;
|
||||
}
|
||||
export {
|
||||
ProcessCloudIdeProvider
|
||||
};
|
||||
8
node_modules/astro/dist/cli/domain/command.d.ts
generated
vendored
Normal file
8
node_modules/astro/dist/cli/domain/command.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import type { HelpPayload } from './help-payload.js';
|
||||
interface Command<T extends (...args: Array<any>) => any> {
|
||||
help: HelpPayload;
|
||||
run: T;
|
||||
}
|
||||
export type AnyCommand = Command<(...args: Array<any>) => any>;
|
||||
export declare function defineCommand<T extends AnyCommand>(command: T): T;
|
||||
export {};
|
||||
6
node_modules/astro/dist/cli/domain/command.js
generated
vendored
Normal file
6
node_modules/astro/dist/cli/domain/command.js
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
function defineCommand(command) {
|
||||
return command;
|
||||
}
|
||||
export {
|
||||
defineCommand
|
||||
};
|
||||
7
node_modules/astro/dist/cli/domain/help-payload.d.ts
generated
vendored
Normal file
7
node_modules/astro/dist/cli/domain/help-payload.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
export interface HelpPayload {
|
||||
commandName: string;
|
||||
headline?: string;
|
||||
usage?: string;
|
||||
tables?: Record<string, [command: string, help: string][]>;
|
||||
description?: string;
|
||||
}
|
||||
0
node_modules/astro/dist/cli/domain/help-payload.js
generated
vendored
Normal file
0
node_modules/astro/dist/cli/domain/help-payload.js
generated
vendored
Normal file
6
node_modules/astro/dist/cli/exec.d.ts
generated
vendored
Normal file
6
node_modules/astro/dist/cli/exec.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import { type Options } from 'tinyexec';
|
||||
/**
|
||||
* Improve tinyexec error logging and set `throwOnError` to `true` by default
|
||||
* @deprecated use CommandExecutor instead
|
||||
*/
|
||||
export declare function exec(command: string, args?: string[], options?: Partial<Options>): PromiseLike<import("tinyexec").Output>;
|
||||
23
node_modules/astro/dist/cli/exec.js
generated
vendored
Normal file
23
node_modules/astro/dist/cli/exec.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
import { NonZeroExitError, x } from "tinyexec";
|
||||
function exec(command, args, options) {
|
||||
return x(command, args, {
|
||||
throwOnError: true,
|
||||
...options
|
||||
}).then(
|
||||
(o) => o,
|
||||
(e) => {
|
||||
if (e instanceof NonZeroExitError) {
|
||||
const fullCommand = args?.length ? `${command} ${args.map((a) => a.includes(" ") ? `"${a}"` : a).join(" ")}` : command;
|
||||
const message = `The command \`${fullCommand}\` exited with code ${e.exitCode}`;
|
||||
const newError = new Error(message, e.cause ? { cause: e.cause } : void 0);
|
||||
newError.stderr = e.output?.stderr;
|
||||
newError.stdout = e.output?.stdout;
|
||||
throw newError;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
);
|
||||
}
|
||||
export {
|
||||
exec
|
||||
};
|
||||
11
node_modules/astro/dist/cli/flags.d.ts
generated
vendored
Normal file
11
node_modules/astro/dist/cli/flags.d.ts
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
import type { Arguments } from 'yargs-parser';
|
||||
import { Logger } from '../core/logger/core.js';
|
||||
import type { AstroInlineConfig } from '../types/public/config.js';
|
||||
export type Flags = Arguments;
|
||||
/** @deprecated Use AstroConfigResolver instead */
|
||||
export declare function flagsToAstroInlineConfig(flags: Flags): AstroInlineConfig;
|
||||
/**
|
||||
* The `logging` is usually created from an `AstroInlineConfig`, but some flows like `add`
|
||||
* doesn't read the AstroConfig directly, so we create a `logging` object from the CLI flags instead.
|
||||
*/
|
||||
export declare function createLoggerFromFlags(flags: Flags): Logger;
|
||||
38
node_modules/astro/dist/cli/flags.js
generated
vendored
Normal file
38
node_modules/astro/dist/cli/flags.js
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
import { Logger } from "../core/logger/core.js";
|
||||
import { nodeLogDestination } from "../core/logger/node.js";
|
||||
function flagsToAstroInlineConfig(flags) {
|
||||
return {
|
||||
// Inline-only configs
|
||||
configFile: typeof flags.config === "string" ? flags.config : void 0,
|
||||
mode: typeof flags.mode === "string" ? flags.mode : void 0,
|
||||
logLevel: flags.verbose ? "debug" : flags.silent ? "silent" : void 0,
|
||||
force: flags.force ? true : void 0,
|
||||
// Astro user configs
|
||||
root: typeof flags.root === "string" ? flags.root : void 0,
|
||||
site: typeof flags.site === "string" ? flags.site : void 0,
|
||||
base: typeof flags.base === "string" ? flags.base : void 0,
|
||||
outDir: typeof flags.outDir === "string" ? flags.outDir : void 0,
|
||||
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,
|
||||
allowedHosts: typeof flags.allowedHosts === "string" ? flags.allowedHosts.split(",") : typeof flags.allowedHosts === "boolean" && flags.allowedHosts === true ? flags.allowedHosts : []
|
||||
}
|
||||
};
|
||||
}
|
||||
function createLoggerFromFlags(flags) {
|
||||
const logging = {
|
||||
dest: nodeLogDestination,
|
||||
level: "info"
|
||||
};
|
||||
if (flags.verbose) {
|
||||
logging.level = "debug";
|
||||
} else if (flags.silent) {
|
||||
logging.level = "silent";
|
||||
}
|
||||
return new Logger(logging);
|
||||
}
|
||||
export {
|
||||
createLoggerFromFlags,
|
||||
flagsToAstroInlineConfig
|
||||
};
|
||||
2
node_modules/astro/dist/cli/help/index.d.ts
generated
vendored
Normal file
2
node_modules/astro/dist/cli/help/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import type { HelpPayload } from '../domain/help-payload.js';
|
||||
export declare const DEFAULT_HELP_PAYLOAD: HelpPayload;
|
||||
34
node_modules/astro/dist/cli/help/index.js
generated
vendored
Normal file
34
node_modules/astro/dist/cli/help/index.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
const DEFAULT_HELP_PAYLOAD = {
|
||||
commandName: "astro",
|
||||
usage: "[command] [...flags]",
|
||||
headline: "Build faster websites.",
|
||||
tables: {
|
||||
Commands: [
|
||||
["add", "Add an integration."],
|
||||
["build", "Build your project and write it to disk."],
|
||||
["check", "Check your project for errors."],
|
||||
["create-key", "Create a cryptography key"],
|
||||
["db", "Manage your Astro database."],
|
||||
["dev", "Start the development server."],
|
||||
["docs", "Open documentation in your web browser."],
|
||||
["info", "List info about your current Astro setup."],
|
||||
["preview", "Preview your build locally."],
|
||||
["sync", "Generate content collection types."],
|
||||
["preferences", "Configure user preferences."],
|
||||
["telemetry", "Configure telemetry settings."]
|
||||
],
|
||||
"Global Flags": [
|
||||
["--config <path>", "Specify your config file."],
|
||||
["--root <path>", "Specify your project root folder."],
|
||||
["--site <url>", "Specify your project site."],
|
||||
["--base <pathname>", "Specify your project base."],
|
||||
["--verbose", "Enable verbose logging."],
|
||||
["--silent", "Disable all logging."],
|
||||
["--version", "Show the version number and exit."],
|
||||
["--help", "Show this help message."]
|
||||
]
|
||||
}
|
||||
};
|
||||
export {
|
||||
DEFAULT_HELP_PAYLOAD
|
||||
};
|
||||
2
node_modules/astro/dist/cli/index.d.ts
generated
vendored
Normal file
2
node_modules/astro/dist/cli/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/** The primary CLI action */
|
||||
export declare function cli(argv: string[]): Promise<void>;
|
||||
246
node_modules/astro/dist/cli/index.js
generated
vendored
Normal file
246
node_modules/astro/dist/cli/index.js
generated
vendored
Normal file
@@ -0,0 +1,246 @@
|
||||
import yargs from "yargs-parser";
|
||||
import { apply as applyPolyfill } from "../core/polyfill.js";
|
||||
function resolveCommand(flags) {
|
||||
const cmd = flags._[2];
|
||||
if (flags.version) return "version";
|
||||
const supportedCommands = /* @__PURE__ */ new Set([
|
||||
"add",
|
||||
"sync",
|
||||
"telemetry",
|
||||
"preferences",
|
||||
"dev",
|
||||
"build",
|
||||
"preview",
|
||||
"check",
|
||||
"create-key",
|
||||
"docs",
|
||||
"db",
|
||||
"info",
|
||||
"login",
|
||||
"logout",
|
||||
"link",
|
||||
"init"
|
||||
]);
|
||||
if (supportedCommands.has(cmd)) {
|
||||
return cmd;
|
||||
}
|
||||
return "help";
|
||||
}
|
||||
async function runCommand(cmd, flags) {
|
||||
applyPolyfill();
|
||||
const [
|
||||
{ createLoggerFromFlags },
|
||||
{ piccoloreTextStyler: textStyler },
|
||||
{ BuildTimeAstroVersionProvider },
|
||||
{ LoggerHelpDisplay },
|
||||
{ CliCommandRunner }
|
||||
] = await Promise.all([
|
||||
import("./flags.js"),
|
||||
import("./infra/piccolore-text-styler.js"),
|
||||
import("./infra/build-time-astro-version-provider.js"),
|
||||
import("./infra/logger-help-display.js"),
|
||||
import("./infra/cli-command-runner.js")
|
||||
]);
|
||||
const logger = createLoggerFromFlags(flags);
|
||||
const astroVersionProvider = new BuildTimeAstroVersionProvider();
|
||||
const helpDisplay = new LoggerHelpDisplay({
|
||||
logger,
|
||||
flags,
|
||||
textStyler,
|
||||
astroVersionProvider
|
||||
});
|
||||
const runner = new CliCommandRunner({ helpDisplay });
|
||||
switch (cmd) {
|
||||
/** Display --help flag */
|
||||
case "help": {
|
||||
const { DEFAULT_HELP_PAYLOAD } = await import("./help/index.js");
|
||||
helpDisplay.show(DEFAULT_HELP_PAYLOAD);
|
||||
return;
|
||||
}
|
||||
/** Display --version flag */
|
||||
case "version": {
|
||||
const { formatVersion } = await import("./utils/format-version.js");
|
||||
logger.info(
|
||||
"SKIP_FORMAT",
|
||||
formatVersion({ name: "astro", textStyler, astroVersionProvider })
|
||||
);
|
||||
return;
|
||||
}
|
||||
case "info": {
|
||||
const [
|
||||
{ ProcessOperatingSystemProvider },
|
||||
{ CliAstroConfigResolver },
|
||||
{ ProcessPackageManagerUserAgentProvider },
|
||||
{ ProcessNodeVersionProvider },
|
||||
{ CliDebugInfoProvider },
|
||||
{ TinyexecCommandExecutor },
|
||||
{ getPackageManager },
|
||||
{ StyledDebugInfoFormatter },
|
||||
{ PromptsPrompt },
|
||||
{ CliClipboard },
|
||||
{ PassthroughTextStyler },
|
||||
{ infoCommand }
|
||||
] = await Promise.all([
|
||||
import("./infra/process-operating-system-provider.js"),
|
||||
import("./info/infra/cli-astro-config-resolver.js"),
|
||||
import("./info/infra/process-package-manager-user-agent-provider.js"),
|
||||
import("./info/infra/process-node-version-provider.js"),
|
||||
import("./info/infra/cli-debug-info-provider.js"),
|
||||
import("./infra/tinyexec-command-executor.js"),
|
||||
import("./info/core/get-package-manager.js"),
|
||||
import("./info/infra/styled-debug-info-formatter.js"),
|
||||
import("./info/infra/prompts-prompt.js"),
|
||||
import("./info/infra/cli-clipboard.js"),
|
||||
import("./infra/passthrough-text-styler.js"),
|
||||
import("./info/core/info.js")
|
||||
]);
|
||||
const operatingSystemProvider = new ProcessOperatingSystemProvider();
|
||||
const astroConfigResolver = new CliAstroConfigResolver({ flags });
|
||||
const commandExecutor = new TinyexecCommandExecutor();
|
||||
const packageManagerUserAgentProvider = new ProcessPackageManagerUserAgentProvider();
|
||||
const nodeVersionProvider = new ProcessNodeVersionProvider();
|
||||
const debugInfoProvider = new CliDebugInfoProvider({
|
||||
config: await astroConfigResolver.resolve(),
|
||||
astroVersionProvider,
|
||||
operatingSystemProvider,
|
||||
packageManager: await getPackageManager({
|
||||
packageManagerUserAgentProvider,
|
||||
commandExecutor
|
||||
}),
|
||||
nodeVersionProvider
|
||||
});
|
||||
const prompt = new PromptsPrompt({ force: flags.copy });
|
||||
const clipboard = new CliClipboard({
|
||||
commandExecutor,
|
||||
logger,
|
||||
operatingSystemProvider,
|
||||
prompt
|
||||
});
|
||||
return await runner.run(infoCommand, {
|
||||
logger,
|
||||
debugInfoProvider,
|
||||
getDebugInfoFormatter: ({ pretty }) => new StyledDebugInfoFormatter({
|
||||
textStyler: pretty ? textStyler : new PassthroughTextStyler()
|
||||
}),
|
||||
clipboard
|
||||
});
|
||||
}
|
||||
case "create-key": {
|
||||
const [{ CryptoKeyGenerator }, { createKeyCommand }] = await Promise.all([
|
||||
import("./create-key/infra/crypto-key-generator.js"),
|
||||
import("./create-key/core/create-key.js")
|
||||
]);
|
||||
const keyGenerator = new CryptoKeyGenerator();
|
||||
return await runner.run(createKeyCommand, { logger, keyGenerator });
|
||||
}
|
||||
case "docs": {
|
||||
const [
|
||||
{ TinyexecCommandExecutor },
|
||||
{ ProcessOperatingSystemProvider },
|
||||
{ ProcessCloudIdeProvider },
|
||||
{ openDocsCommand }
|
||||
] = await Promise.all([
|
||||
import("./infra/tinyexec-command-executor.js"),
|
||||
import("./infra/process-operating-system-provider.js"),
|
||||
import("./docs/infra/process-cloud-ide-provider.js"),
|
||||
import("./docs/core/open-docs.js")
|
||||
]);
|
||||
const commandExecutor = new TinyexecCommandExecutor();
|
||||
const operatingSystemProvider = new ProcessOperatingSystemProvider();
|
||||
const cloudIdeProvider = new ProcessCloudIdeProvider();
|
||||
return await runner.run(openDocsCommand, {
|
||||
url: "https://docs.astro.build/",
|
||||
logger,
|
||||
commandExecutor,
|
||||
operatingSystemProvider,
|
||||
cloudIdeProvider
|
||||
});
|
||||
}
|
||||
case "telemetry": {
|
||||
const { update } = await import("./telemetry/index.js");
|
||||
const subcommand = flags._[3]?.toString();
|
||||
await update(subcommand, { flags });
|
||||
return;
|
||||
}
|
||||
case "sync": {
|
||||
const { sync } = await import("./sync/index.js");
|
||||
await sync({ flags });
|
||||
return;
|
||||
}
|
||||
case "preferences": {
|
||||
const { preferences } = await import("./preferences/index.js");
|
||||
const [subcommand, key, value] = flags._.slice(3).map((v) => v.toString());
|
||||
const exitCode = await preferences(subcommand, key, value, { flags });
|
||||
return process.exit(exitCode);
|
||||
}
|
||||
}
|
||||
if (flags.verbose) {
|
||||
const { enableVerboseLogging } = await import("../core/logger/node.js");
|
||||
enableVerboseLogging();
|
||||
}
|
||||
const { notify } = await import("./telemetry/index.js");
|
||||
await notify();
|
||||
switch (cmd) {
|
||||
case "add": {
|
||||
const { add } = await import("./add/index.js");
|
||||
const packages = flags._.slice(3);
|
||||
await add(packages, { flags });
|
||||
return;
|
||||
}
|
||||
case "db":
|
||||
case "login":
|
||||
case "logout":
|
||||
case "link":
|
||||
case "init": {
|
||||
const { db } = await import("./db/index.js");
|
||||
await db({ flags });
|
||||
return;
|
||||
}
|
||||
case "dev": {
|
||||
const { dev } = await import("./dev/index.js");
|
||||
const server = await dev({ flags });
|
||||
if (server) {
|
||||
return await new Promise(() => {
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
case "build": {
|
||||
const { build } = await import("./build/index.js");
|
||||
await build({ flags });
|
||||
return;
|
||||
}
|
||||
case "preview": {
|
||||
const { preview } = await import("./preview/index.js");
|
||||
const server = await preview({ flags });
|
||||
if (server) {
|
||||
return await server.closed();
|
||||
}
|
||||
return;
|
||||
}
|
||||
case "check": {
|
||||
const { check } = await import("./check/index.js");
|
||||
const checkServer = await check(flags);
|
||||
if (flags.watch) {
|
||||
return await new Promise(() => {
|
||||
});
|
||||
} else {
|
||||
return process.exit(typeof checkServer === "boolean" && checkServer ? 1 : 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new Error(`Error running ${cmd} -- no command found.`);
|
||||
}
|
||||
async function cli(argv) {
|
||||
const flags = yargs(argv, { boolean: ["global"], alias: { g: "global" } });
|
||||
const cmd = resolveCommand(flags);
|
||||
try {
|
||||
await runCommand(cmd, flags);
|
||||
} catch (err) {
|
||||
const { throwAndExit } = await import("./throw-and-exit.js");
|
||||
await throwAndExit(cmd, err);
|
||||
}
|
||||
}
|
||||
export {
|
||||
cli
|
||||
};
|
||||
8
node_modules/astro/dist/cli/info/core/get-package-manager.d.ts
generated
vendored
Normal file
8
node_modules/astro/dist/cli/info/core/get-package-manager.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import type { CommandExecutor } from '../../definitions.js';
|
||||
import type { PackageManager, PackageManagerUserAgentProvider } from '../definitions.js';
|
||||
interface Options {
|
||||
packageManagerUserAgentProvider: PackageManagerUserAgentProvider;
|
||||
commandExecutor: CommandExecutor;
|
||||
}
|
||||
export declare function getPackageManager({ packageManagerUserAgentProvider, commandExecutor, }: Options): Promise<PackageManager>;
|
||||
export {};
|
||||
37
node_modules/astro/dist/cli/info/core/get-package-manager.js
generated
vendored
Normal file
37
node_modules/astro/dist/cli/info/core/get-package-manager.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
async function getPackageManager({
|
||||
packageManagerUserAgentProvider,
|
||||
commandExecutor
|
||||
}) {
|
||||
if (!packageManagerUserAgentProvider.userAgent) {
|
||||
const { NoopPackageManager } = await import("../infra/noop-package-manager.js");
|
||||
return new NoopPackageManager();
|
||||
}
|
||||
const specifier = packageManagerUserAgentProvider.userAgent.split(" ")[0];
|
||||
const _name = specifier.substring(0, specifier.lastIndexOf("/"));
|
||||
const name = _name === "npminstall" ? "cnpm" : _name;
|
||||
switch (name) {
|
||||
case "pnpm": {
|
||||
const { PnpmPackageManager } = await import("../infra/pnpm-package-manager.js");
|
||||
return new PnpmPackageManager({ commandExecutor });
|
||||
}
|
||||
case "npm": {
|
||||
const { NpmPackageManager } = await import("../infra/npm-package-manager.js");
|
||||
return new NpmPackageManager({ commandExecutor });
|
||||
}
|
||||
case "yarn": {
|
||||
const { YarnPackageManager } = await import("../infra/yarn-package-manager.js");
|
||||
return new YarnPackageManager({ commandExecutor });
|
||||
}
|
||||
case "bun": {
|
||||
const { BunPackageManager } = await import("../infra/bun-package-manager.js");
|
||||
return new BunPackageManager();
|
||||
}
|
||||
default: {
|
||||
const { NoopPackageManager } = await import("../infra/noop-package-manager.js");
|
||||
return new NoopPackageManager();
|
||||
}
|
||||
}
|
||||
}
|
||||
export {
|
||||
getPackageManager
|
||||
};
|
||||
21
node_modules/astro/dist/cli/info/core/info.d.ts
generated
vendored
Normal file
21
node_modules/astro/dist/cli/info/core/info.d.ts
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
import type { Logger } from '../../../core/logger/core.js';
|
||||
import type { Clipboard, DebugInfoFormatter, DebugInfoProvider } from '../definitions.js';
|
||||
interface Options {
|
||||
debugInfoProvider: DebugInfoProvider;
|
||||
getDebugInfoFormatter: (options: {
|
||||
pretty: boolean;
|
||||
}) => DebugInfoFormatter;
|
||||
logger: Logger;
|
||||
clipboard: Clipboard;
|
||||
}
|
||||
export declare const infoCommand: {
|
||||
help: {
|
||||
commandName: string;
|
||||
tables: {
|
||||
Flags: [string, string][];
|
||||
};
|
||||
description: string;
|
||||
};
|
||||
run({ debugInfoProvider, getDebugInfoFormatter, logger, clipboard }: Options): Promise<void>;
|
||||
};
|
||||
export {};
|
||||
21
node_modules/astro/dist/cli/info/core/info.js
generated
vendored
Normal file
21
node_modules/astro/dist/cli/info/core/info.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
import { defineCommand } from "../../domain/command.js";
|
||||
const infoCommand = defineCommand({
|
||||
help: {
|
||||
commandName: "astro info",
|
||||
tables: {
|
||||
Flags: [
|
||||
["--help (-h)", "See all available flags."],
|
||||
["--copy", "Force copy of the output."]
|
||||
]
|
||||
},
|
||||
description: "Reports useful information about your current Astro environment. Useful for providing information when opening an issue."
|
||||
},
|
||||
async run({ debugInfoProvider, getDebugInfoFormatter, logger, clipboard }) {
|
||||
const debugInfo = await debugInfoProvider.get();
|
||||
logger.info("SKIP_FORMAT", getDebugInfoFormatter({ pretty: true }).format(debugInfo));
|
||||
await clipboard.copy(getDebugInfoFormatter({ pretty: false }).format(debugInfo));
|
||||
}
|
||||
});
|
||||
export {
|
||||
infoCommand
|
||||
};
|
||||
30
node_modules/astro/dist/cli/info/definitions.d.ts
generated
vendored
Normal file
30
node_modules/astro/dist/cli/info/definitions.d.ts
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
import type { AstroConfig } from '../../types/public/index.js';
|
||||
import type { DebugInfo } from './domain/debug-info.js';
|
||||
export interface DebugInfoProvider {
|
||||
get: () => Promise<DebugInfo>;
|
||||
}
|
||||
export interface DebugInfoFormatter {
|
||||
format: (info: DebugInfo) => string;
|
||||
}
|
||||
export interface Clipboard {
|
||||
copy: (text: string) => Promise<void>;
|
||||
}
|
||||
export interface PackageManager {
|
||||
readonly name: string;
|
||||
getPackageVersion: (name: string) => Promise<string | undefined>;
|
||||
}
|
||||
export interface AstroConfigResolver {
|
||||
resolve: () => Promise<AstroConfig>;
|
||||
}
|
||||
export interface Prompt {
|
||||
confirm: (input: {
|
||||
message: string;
|
||||
defaultValue?: boolean;
|
||||
}) => Promise<boolean>;
|
||||
}
|
||||
export interface PackageManagerUserAgentProvider {
|
||||
readonly userAgent: string | null;
|
||||
}
|
||||
export interface NodeVersionProvider {
|
||||
readonly version: string;
|
||||
}
|
||||
0
node_modules/astro/dist/cli/info/definitions.js
generated
vendored
Normal file
0
node_modules/astro/dist/cli/info/definitions.js
generated
vendored
Normal file
1
node_modules/astro/dist/cli/info/domain/debug-info.d.ts
generated
vendored
Normal file
1
node_modules/astro/dist/cli/info/domain/debug-info.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export type DebugInfo = Array<[string, string | Array<string>]>;
|
||||
0
node_modules/astro/dist/cli/info/domain/debug-info.js
generated
vendored
Normal file
0
node_modules/astro/dist/cli/info/domain/debug-info.js
generated
vendored
Normal file
5
node_modules/astro/dist/cli/info/infra/bun-package-manager.d.ts
generated
vendored
Normal file
5
node_modules/astro/dist/cli/info/infra/bun-package-manager.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import type { PackageManager } from '../definitions.js';
|
||||
export declare class BunPackageManager implements PackageManager {
|
||||
readonly name: string;
|
||||
getPackageVersion(): Promise<string | undefined>;
|
||||
}
|
||||
9
node_modules/astro/dist/cli/info/infra/bun-package-manager.js
generated
vendored
Normal file
9
node_modules/astro/dist/cli/info/infra/bun-package-manager.js
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
class BunPackageManager {
|
||||
name = "bun";
|
||||
async getPackageVersion() {
|
||||
return void 0;
|
||||
}
|
||||
}
|
||||
export {
|
||||
BunPackageManager
|
||||
};
|
||||
10
node_modules/astro/dist/cli/info/infra/cli-astro-config-resolver.d.ts
generated
vendored
Normal file
10
node_modules/astro/dist/cli/info/infra/cli-astro-config-resolver.d.ts
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import type { AstroConfig } from '../../../types/public/index.js';
|
||||
import type { Flags } from '../../flags.js';
|
||||
import type { AstroConfigResolver } from '../definitions.js';
|
||||
export declare class CliAstroConfigResolver implements AstroConfigResolver {
|
||||
#private;
|
||||
constructor({ flags }: {
|
||||
flags: Flags;
|
||||
});
|
||||
resolve(): Promise<AstroConfig>;
|
||||
}
|
||||
36
node_modules/astro/dist/cli/info/infra/cli-astro-config-resolver.js
generated
vendored
Normal file
36
node_modules/astro/dist/cli/info/infra/cli-astro-config-resolver.js
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
import { resolveConfig } from "../../../core/config/config.js";
|
||||
class CliAstroConfigResolver {
|
||||
// TODO: find something better
|
||||
#flags;
|
||||
constructor({ flags }) {
|
||||
this.#flags = flags;
|
||||
}
|
||||
async resolve() {
|
||||
const { astroConfig } = await resolveConfig(
|
||||
// TODO: consider testing flags => astro inline config
|
||||
{
|
||||
// Inline-only configs
|
||||
configFile: typeof this.#flags.config === "string" ? this.#flags.config : void 0,
|
||||
mode: typeof this.#flags.mode === "string" ? this.#flags.mode : void 0,
|
||||
logLevel: this.#flags.verbose ? "debug" : this.#flags.silent ? "silent" : void 0,
|
||||
force: this.#flags.force ? true : void 0,
|
||||
// Astro user configs
|
||||
root: typeof this.#flags.root === "string" ? this.#flags.root : void 0,
|
||||
site: typeof this.#flags.site === "string" ? this.#flags.site : void 0,
|
||||
base: typeof this.#flags.base === "string" ? this.#flags.base : void 0,
|
||||
outDir: typeof this.#flags.outDir === "string" ? this.#flags.outDir : void 0,
|
||||
server: {
|
||||
port: typeof this.#flags.port === "number" ? this.#flags.port : void 0,
|
||||
host: typeof this.#flags.host === "string" || typeof this.#flags.host === "boolean" ? this.#flags.host : void 0,
|
||||
open: typeof this.#flags.open === "string" || typeof this.#flags.open === "boolean" ? this.#flags.open : void 0,
|
||||
allowedHosts: typeof this.#flags.allowedHosts === "string" ? this.#flags.allowedHosts.split(",") : typeof this.#flags.allowedHosts === "boolean" && this.#flags.allowedHosts === true ? this.#flags.allowedHosts : []
|
||||
}
|
||||
},
|
||||
"info"
|
||||
);
|
||||
return astroConfig;
|
||||
}
|
||||
}
|
||||
export {
|
||||
CliAstroConfigResolver
|
||||
};
|
||||
13
node_modules/astro/dist/cli/info/infra/cli-clipboard.d.ts
generated
vendored
Normal file
13
node_modules/astro/dist/cli/info/infra/cli-clipboard.d.ts
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import type { Logger } from '../../../core/logger/core.js';
|
||||
import type { CommandExecutor, OperatingSystemProvider } from '../../definitions.js';
|
||||
import type { Clipboard, Prompt } from '../definitions.js';
|
||||
export declare class CliClipboard implements Clipboard {
|
||||
#private;
|
||||
constructor({ operatingSystemProvider, commandExecutor, logger, prompt, }: {
|
||||
operatingSystemProvider: OperatingSystemProvider;
|
||||
commandExecutor: CommandExecutor;
|
||||
logger: Logger;
|
||||
prompt: Prompt;
|
||||
});
|
||||
copy(text: string): Promise<void>;
|
||||
}
|
||||
78
node_modules/astro/dist/cli/info/infra/cli-clipboard.js
generated
vendored
Normal file
78
node_modules/astro/dist/cli/info/infra/cli-clipboard.js
generated
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
async function getExecInputForPlatform({
|
||||
platform,
|
||||
commandExecutor
|
||||
}) {
|
||||
if (platform === "darwin") {
|
||||
return ["pbcopy"];
|
||||
}
|
||||
if (platform === "win32") {
|
||||
return ["clip"];
|
||||
}
|
||||
const unixCommands = [
|
||||
["xclip", ["-selection", "clipboard"]],
|
||||
["wl-copy", []]
|
||||
];
|
||||
for (const [unixCommand, unixArgs] of unixCommands) {
|
||||
try {
|
||||
const { stdout } = await commandExecutor.execute("which", [unixCommand]);
|
||||
if (stdout.trim()) {
|
||||
return [unixCommand, unixArgs];
|
||||
}
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
class CliClipboard {
|
||||
#operatingSystemProvider;
|
||||
#commandExecutor;
|
||||
#logger;
|
||||
#prompt;
|
||||
constructor({
|
||||
operatingSystemProvider,
|
||||
commandExecutor,
|
||||
logger,
|
||||
prompt
|
||||
}) {
|
||||
this.#operatingSystemProvider = operatingSystemProvider;
|
||||
this.#commandExecutor = commandExecutor;
|
||||
this.#logger = logger;
|
||||
this.#prompt = prompt;
|
||||
}
|
||||
async copy(text) {
|
||||
text = text.trim();
|
||||
const platform = this.#operatingSystemProvider.name;
|
||||
const input = await getExecInputForPlatform({
|
||||
platform,
|
||||
commandExecutor: this.#commandExecutor
|
||||
});
|
||||
if (!input) {
|
||||
this.#logger.warn("SKIP_FORMAT", "Clipboard command not found!");
|
||||
this.#logger.info("SKIP_FORMAT", "Please manually copy the text above.");
|
||||
return;
|
||||
}
|
||||
if (!await this.#prompt.confirm({
|
||||
message: "Copy to clipboard?",
|
||||
defaultValue: true
|
||||
})) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const [command, args] = input;
|
||||
await this.#commandExecutor.execute(command, args, {
|
||||
input: text,
|
||||
stdio: ["pipe", "ignore", "ignore"]
|
||||
});
|
||||
this.#logger.info("SKIP_FORMAT", "Copied to clipboard!");
|
||||
} catch {
|
||||
this.#logger.error(
|
||||
"SKIP_FORMAT",
|
||||
"Sorry, something went wrong! Please copy the text above manually."
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
export {
|
||||
CliClipboard
|
||||
};
|
||||
15
node_modules/astro/dist/cli/info/infra/cli-debug-info-provider.d.ts
generated
vendored
Normal file
15
node_modules/astro/dist/cli/info/infra/cli-debug-info-provider.d.ts
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
import type { AstroConfig } from '../../../types/public/index.js';
|
||||
import type { AstroVersionProvider, OperatingSystemProvider } from '../../definitions.js';
|
||||
import type { DebugInfoProvider, NodeVersionProvider, PackageManager } from '../definitions.js';
|
||||
import type { DebugInfo } from '../domain/debug-info.js';
|
||||
export declare class CliDebugInfoProvider implements DebugInfoProvider {
|
||||
#private;
|
||||
constructor({ config, astroVersionProvider, packageManager, operatingSystemProvider, nodeVersionProvider, }: {
|
||||
config: Pick<AstroConfig, 'output' | 'adapter' | 'integrations'>;
|
||||
astroVersionProvider: AstroVersionProvider;
|
||||
packageManager: PackageManager;
|
||||
operatingSystemProvider: OperatingSystemProvider;
|
||||
nodeVersionProvider: NodeVersionProvider;
|
||||
});
|
||||
get(): Promise<DebugInfo>;
|
||||
}
|
||||
57
node_modules/astro/dist/cli/info/infra/cli-debug-info-provider.js
generated
vendored
Normal file
57
node_modules/astro/dist/cli/info/infra/cli-debug-info-provider.js
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
function withVersion(name, version) {
|
||||
let result = name;
|
||||
if (version) {
|
||||
result += ` (${version})`;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
class CliDebugInfoProvider {
|
||||
#config;
|
||||
#astroVersionProvider;
|
||||
#packageManager;
|
||||
#operatingSystemProvider;
|
||||
#nodeVersionProvider;
|
||||
constructor({
|
||||
config,
|
||||
astroVersionProvider,
|
||||
packageManager,
|
||||
operatingSystemProvider,
|
||||
nodeVersionProvider
|
||||
}) {
|
||||
this.#config = config;
|
||||
this.#astroVersionProvider = astroVersionProvider;
|
||||
this.#packageManager = packageManager;
|
||||
this.#operatingSystemProvider = operatingSystemProvider;
|
||||
this.#nodeVersionProvider = nodeVersionProvider;
|
||||
}
|
||||
async get() {
|
||||
const debugInfo = [
|
||||
["Astro", `v${this.#astroVersionProvider.version}`],
|
||||
["Node", this.#nodeVersionProvider.version],
|
||||
["System", this.#operatingSystemProvider.displayName],
|
||||
["Package Manager", this.#packageManager.name],
|
||||
["Output", this.#config.output]
|
||||
];
|
||||
const viteVersion = await this.#packageManager.getPackageVersion("vite");
|
||||
if (viteVersion) {
|
||||
debugInfo.splice(1, 0, ["Vite", viteVersion]);
|
||||
}
|
||||
debugInfo.push([
|
||||
"Adapter",
|
||||
this.#config.adapter ? withVersion(
|
||||
this.#config.adapter.name,
|
||||
await this.#packageManager.getPackageVersion(this.#config.adapter.name)
|
||||
) : "none"
|
||||
]);
|
||||
const integrations = await Promise.all(
|
||||
this.#config.integrations.map(
|
||||
async ({ name }) => withVersion(name, await this.#packageManager.getPackageVersion(name))
|
||||
)
|
||||
);
|
||||
debugInfo.push(["Integrations", integrations.length > 0 ? integrations : "none"]);
|
||||
return debugInfo;
|
||||
}
|
||||
}
|
||||
export {
|
||||
CliDebugInfoProvider
|
||||
};
|
||||
18
node_modules/astro/dist/cli/info/infra/dev-debug-info-provider.d.ts
generated
vendored
Normal file
18
node_modules/astro/dist/cli/info/infra/dev-debug-info-provider.d.ts
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
import type { AstroConfig } from '../../../types/public/index.js';
|
||||
import type { AstroVersionProvider, OperatingSystemProvider } from '../../definitions.js';
|
||||
import type { DebugInfoProvider, NodeVersionProvider, PackageManager } from '../definitions.js';
|
||||
import type { DebugInfo } from '../domain/debug-info.js';
|
||||
/**
|
||||
* Returns debug info without any package versions, to avoid slowing down the dev server
|
||||
*/
|
||||
export declare class DevDebugInfoProvider implements DebugInfoProvider {
|
||||
#private;
|
||||
constructor({ config, astroVersionProvider, packageManager, operatingSystemProvider, nodeVersionProvider, }: {
|
||||
config: Pick<AstroConfig, 'output' | 'adapter' | 'integrations'>;
|
||||
astroVersionProvider: AstroVersionProvider;
|
||||
packageManager: PackageManager;
|
||||
operatingSystemProvider: OperatingSystemProvider;
|
||||
nodeVersionProvider: NodeVersionProvider;
|
||||
});
|
||||
get(): Promise<DebugInfo>;
|
||||
}
|
||||
36
node_modules/astro/dist/cli/info/infra/dev-debug-info-provider.js
generated
vendored
Normal file
36
node_modules/astro/dist/cli/info/infra/dev-debug-info-provider.js
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
class DevDebugInfoProvider {
|
||||
#config;
|
||||
#astroVersionProvider;
|
||||
#packageManager;
|
||||
#operatingSystemProvider;
|
||||
#nodeVersionProvider;
|
||||
constructor({
|
||||
config,
|
||||
astroVersionProvider,
|
||||
packageManager,
|
||||
operatingSystemProvider,
|
||||
nodeVersionProvider
|
||||
}) {
|
||||
this.#config = config;
|
||||
this.#astroVersionProvider = astroVersionProvider;
|
||||
this.#packageManager = packageManager;
|
||||
this.#operatingSystemProvider = operatingSystemProvider;
|
||||
this.#nodeVersionProvider = nodeVersionProvider;
|
||||
}
|
||||
async get() {
|
||||
const debugInfo = [
|
||||
["Astro", `v${this.#astroVersionProvider.version}`],
|
||||
["Node", this.#nodeVersionProvider.version],
|
||||
["System", this.#operatingSystemProvider.displayName],
|
||||
["Package Manager", this.#packageManager.name],
|
||||
["Output", this.#config.output],
|
||||
["Adapter", this.#config.adapter?.name ?? "none"]
|
||||
];
|
||||
const integrations = this.#config.integrations.map((integration) => integration.name);
|
||||
debugInfo.push(["Integrations", integrations.length > 0 ? integrations : "none"]);
|
||||
return debugInfo;
|
||||
}
|
||||
}
|
||||
export {
|
||||
DevDebugInfoProvider
|
||||
};
|
||||
5
node_modules/astro/dist/cli/info/infra/noop-package-manager.d.ts
generated
vendored
Normal file
5
node_modules/astro/dist/cli/info/infra/noop-package-manager.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import type { PackageManager } from '../definitions.js';
|
||||
export declare class NoopPackageManager implements PackageManager {
|
||||
readonly name: string;
|
||||
getPackageVersion(): Promise<string | undefined>;
|
||||
}
|
||||
9
node_modules/astro/dist/cli/info/infra/noop-package-manager.js
generated
vendored
Normal file
9
node_modules/astro/dist/cli/info/infra/noop-package-manager.js
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
class NoopPackageManager {
|
||||
name = "unknown";
|
||||
async getPackageVersion() {
|
||||
return void 0;
|
||||
}
|
||||
}
|
||||
export {
|
||||
NoopPackageManager
|
||||
};
|
||||
10
node_modules/astro/dist/cli/info/infra/npm-package-manager.d.ts
generated
vendored
Normal file
10
node_modules/astro/dist/cli/info/infra/npm-package-manager.d.ts
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import type { CommandExecutor } from '../../definitions.js';
|
||||
import type { PackageManager } from '../definitions.js';
|
||||
export declare class NpmPackageManager implements PackageManager {
|
||||
#private;
|
||||
readonly name: string;
|
||||
constructor({ commandExecutor }: {
|
||||
commandExecutor: CommandExecutor;
|
||||
});
|
||||
getPackageVersion(name: string): Promise<string | undefined>;
|
||||
}
|
||||
32
node_modules/astro/dist/cli/info/infra/npm-package-manager.js
generated
vendored
Normal file
32
node_modules/astro/dist/cli/info/infra/npm-package-manager.js
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
class NpmPackageManager {
|
||||
name = "npm";
|
||||
#commandExecutor;
|
||||
constructor({ commandExecutor }) {
|
||||
this.#commandExecutor = commandExecutor;
|
||||
}
|
||||
async getPackageVersion(name) {
|
||||
try {
|
||||
const { stdout } = await this.#commandExecutor.execute(
|
||||
"npm",
|
||||
["ls", name, "--json", "--depth=1"],
|
||||
{
|
||||
shell: true
|
||||
}
|
||||
);
|
||||
const parsedNpmOutput = JSON.parse(stdout);
|
||||
if (!parsedNpmOutput.dependencies) {
|
||||
return void 0;
|
||||
}
|
||||
if (parsedNpmOutput.dependencies[name]) {
|
||||
return `v${parsedNpmOutput.dependencies[name].version}`;
|
||||
}
|
||||
const astro = parsedNpmOutput.dependencies.astro;
|
||||
return astro ? `v${astro.dependencies[name].version}` : void 0;
|
||||
} catch {
|
||||
return void 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
export {
|
||||
NpmPackageManager
|
||||
};
|
||||
10
node_modules/astro/dist/cli/info/infra/pnpm-package-manager.d.ts
generated
vendored
Normal file
10
node_modules/astro/dist/cli/info/infra/pnpm-package-manager.d.ts
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import type { CommandExecutor } from '../../definitions.js';
|
||||
import type { PackageManager } from '../definitions.js';
|
||||
export declare class PnpmPackageManager implements PackageManager {
|
||||
#private;
|
||||
readonly name: string;
|
||||
constructor({ commandExecutor }: {
|
||||
commandExecutor: CommandExecutor;
|
||||
});
|
||||
getPackageVersion(name: string): Promise<string | undefined>;
|
||||
}
|
||||
33
node_modules/astro/dist/cli/info/infra/pnpm-package-manager.js
generated
vendored
Normal file
33
node_modules/astro/dist/cli/info/infra/pnpm-package-manager.js
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
function formatPnpmVersionOutput(versionOutput) {
|
||||
return versionOutput.startsWith("link:") ? "Local" : `v${versionOutput}`;
|
||||
}
|
||||
class PnpmPackageManager {
|
||||
name = "pnpm";
|
||||
#commandExecutor;
|
||||
constructor({ commandExecutor }) {
|
||||
this.#commandExecutor = commandExecutor;
|
||||
}
|
||||
async getPackageVersion(name) {
|
||||
try {
|
||||
const { stdout } = await this.#commandExecutor.execute("pnpm", ["why", name, "--json"], {
|
||||
shell: true
|
||||
});
|
||||
const parsedOutput = JSON.parse(stdout);
|
||||
const deps = parsedOutput[0].dependencies;
|
||||
if (parsedOutput.length === 0 || !deps) {
|
||||
return void 0;
|
||||
}
|
||||
const userProvidedDependency = deps[name];
|
||||
if (userProvidedDependency) {
|
||||
return formatPnpmVersionOutput(userProvidedDependency.version);
|
||||
}
|
||||
const astroDependency = deps.astro?.dependencies[name];
|
||||
return astroDependency ? formatPnpmVersionOutput(astroDependency.version) : void 0;
|
||||
} catch {
|
||||
return void 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
export {
|
||||
PnpmPackageManager
|
||||
};
|
||||
4
node_modules/astro/dist/cli/info/infra/process-node-version-provider.d.ts
generated
vendored
Normal file
4
node_modules/astro/dist/cli/info/infra/process-node-version-provider.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import type { NodeVersionProvider } from '../definitions.js';
|
||||
export declare class ProcessNodeVersionProvider implements NodeVersionProvider {
|
||||
readonly version: string;
|
||||
}
|
||||
6
node_modules/astro/dist/cli/info/infra/process-node-version-provider.js
generated
vendored
Normal file
6
node_modules/astro/dist/cli/info/infra/process-node-version-provider.js
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
class ProcessNodeVersionProvider {
|
||||
version = process.version;
|
||||
}
|
||||
export {
|
||||
ProcessNodeVersionProvider
|
||||
};
|
||||
4
node_modules/astro/dist/cli/info/infra/process-package-manager-user-agent-provider.d.ts
generated
vendored
Normal file
4
node_modules/astro/dist/cli/info/infra/process-package-manager-user-agent-provider.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import type { PackageManagerUserAgentProvider } from '../definitions.js';
|
||||
export declare class ProcessPackageManagerUserAgentProvider implements PackageManagerUserAgentProvider {
|
||||
readonly userAgent: string | null;
|
||||
}
|
||||
7
node_modules/astro/dist/cli/info/infra/process-package-manager-user-agent-provider.js
generated
vendored
Normal file
7
node_modules/astro/dist/cli/info/infra/process-package-manager-user-agent-provider.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
class ProcessPackageManagerUserAgentProvider {
|
||||
// https://docs.npmjs.com/cli/v8/using-npm/config#user-agent
|
||||
userAgent = process.env.npm_config_user_agent ?? null;
|
||||
}
|
||||
export {
|
||||
ProcessPackageManagerUserAgentProvider
|
||||
};
|
||||
11
node_modules/astro/dist/cli/info/infra/prompts-prompt.d.ts
generated
vendored
Normal file
11
node_modules/astro/dist/cli/info/infra/prompts-prompt.d.ts
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
import type { Prompt } from '../definitions.js';
|
||||
export declare class PromptsPrompt implements Prompt {
|
||||
#private;
|
||||
constructor({ force }: {
|
||||
force: boolean;
|
||||
});
|
||||
confirm({ message, defaultValue, }: {
|
||||
message: string;
|
||||
defaultValue?: boolean;
|
||||
}): Promise<boolean>;
|
||||
}
|
||||
25
node_modules/astro/dist/cli/info/infra/prompts-prompt.js
generated
vendored
Normal file
25
node_modules/astro/dist/cli/info/infra/prompts-prompt.js
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
import prompts from "prompts";
|
||||
class PromptsPrompt {
|
||||
#force;
|
||||
constructor({ force }) {
|
||||
this.#force = force;
|
||||
}
|
||||
async confirm({
|
||||
message,
|
||||
defaultValue
|
||||
}) {
|
||||
if (this.#force) {
|
||||
return true;
|
||||
}
|
||||
const { value } = await prompts({
|
||||
type: "confirm",
|
||||
name: "value",
|
||||
message,
|
||||
initial: defaultValue
|
||||
});
|
||||
return value;
|
||||
}
|
||||
}
|
||||
export {
|
||||
PromptsPrompt
|
||||
};
|
||||
10
node_modules/astro/dist/cli/info/infra/styled-debug-info-formatter.d.ts
generated
vendored
Normal file
10
node_modules/astro/dist/cli/info/infra/styled-debug-info-formatter.d.ts
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import type { TextStyler } from '../../definitions.js';
|
||||
import type { DebugInfoFormatter } from '../definitions.js';
|
||||
import type { DebugInfo } from '../domain/debug-info.js';
|
||||
export declare class StyledDebugInfoFormatter implements DebugInfoFormatter {
|
||||
#private;
|
||||
constructor({ textStyler, }: {
|
||||
textStyler: TextStyler;
|
||||
});
|
||||
format(info: DebugInfo): string;
|
||||
}
|
||||
29
node_modules/astro/dist/cli/info/infra/styled-debug-info-formatter.js
generated
vendored
Normal file
29
node_modules/astro/dist/cli/info/infra/styled-debug-info-formatter.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
class StyledDebugInfoFormatter {
|
||||
#textStyler;
|
||||
#maxPadding = 25;
|
||||
constructor({
|
||||
textStyler
|
||||
}) {
|
||||
this.#textStyler = textStyler;
|
||||
}
|
||||
format(info) {
|
||||
let output = "";
|
||||
for (const [label, value] of info) {
|
||||
const padding = this.#maxPadding - label.length;
|
||||
const [first, ...rest] = Array.isArray(value) ? value : [value];
|
||||
let richtext = `
|
||||
${this.#textStyler.bold(label)}${" ".repeat(padding)}${this.#textStyler.green(first)}`;
|
||||
if (rest.length > 0) {
|
||||
for (const entry of rest) {
|
||||
richtext += `
|
||||
${" ".repeat(this.#maxPadding)}${this.#textStyler.green(entry)}`;
|
||||
}
|
||||
}
|
||||
output += richtext;
|
||||
}
|
||||
return output.trim();
|
||||
}
|
||||
}
|
||||
export {
|
||||
StyledDebugInfoFormatter
|
||||
};
|
||||
10
node_modules/astro/dist/cli/info/infra/yarn-package-manager.d.ts
generated
vendored
Normal file
10
node_modules/astro/dist/cli/info/infra/yarn-package-manager.d.ts
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import type { CommandExecutor } from '../../definitions.js';
|
||||
import type { PackageManager } from '../definitions.js';
|
||||
export declare class YarnPackageManager implements PackageManager {
|
||||
#private;
|
||||
readonly name: string;
|
||||
constructor({ commandExecutor }: {
|
||||
commandExecutor: CommandExecutor;
|
||||
});
|
||||
getPackageVersion(name: string): Promise<string | undefined>;
|
||||
}
|
||||
34
node_modules/astro/dist/cli/info/infra/yarn-package-manager.js
generated
vendored
Normal file
34
node_modules/astro/dist/cli/info/infra/yarn-package-manager.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
function getYarnOutputDepVersion(dependency, outputLine) {
|
||||
const parsed = JSON.parse(outputLine);
|
||||
for (const [key, value] of Object.entries(parsed.children)) {
|
||||
if (key.startsWith(`${dependency}@`)) {
|
||||
return `v${value.locator.split(":").pop()}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
class YarnPackageManager {
|
||||
name = "yarn";
|
||||
#commandExecutor;
|
||||
constructor({ commandExecutor }) {
|
||||
this.#commandExecutor = commandExecutor;
|
||||
}
|
||||
async getPackageVersion(name) {
|
||||
try {
|
||||
const { stdout } = await this.#commandExecutor.execute("yarn", ["why", name, "--json"], {
|
||||
shell: true
|
||||
});
|
||||
const hasUserDefinition = stdout.includes("workspace:.");
|
||||
for (const line of stdout.split("\n")) {
|
||||
if (hasUserDefinition && line.includes("workspace:."))
|
||||
return getYarnOutputDepVersion(name, line);
|
||||
if (!hasUserDefinition && line.includes("astro@"))
|
||||
return getYarnOutputDepVersion(name, line);
|
||||
}
|
||||
} catch {
|
||||
return void 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
export {
|
||||
YarnPackageManager
|
||||
};
|
||||
4
node_modules/astro/dist/cli/infra/build-time-astro-version-provider.d.ts
generated
vendored
Normal file
4
node_modules/astro/dist/cli/infra/build-time-astro-version-provider.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import type { AstroVersionProvider } from '../definitions.js';
|
||||
export declare class BuildTimeAstroVersionProvider implements AstroVersionProvider {
|
||||
readonly version: string;
|
||||
}
|
||||
7
node_modules/astro/dist/cli/infra/build-time-astro-version-provider.js
generated
vendored
Normal file
7
node_modules/astro/dist/cli/infra/build-time-astro-version-provider.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
class BuildTimeAstroVersionProvider {
|
||||
// Injected during the build through esbuild define
|
||||
version = "5.17.1";
|
||||
}
|
||||
export {
|
||||
BuildTimeAstroVersionProvider
|
||||
};
|
||||
9
node_modules/astro/dist/cli/infra/cli-command-runner.d.ts
generated
vendored
Normal file
9
node_modules/astro/dist/cli/infra/cli-command-runner.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import type { CommandRunner, HelpDisplay } from '../definitions.js';
|
||||
import type { AnyCommand } from '../domain/command.js';
|
||||
export declare class CliCommandRunner implements CommandRunner {
|
||||
#private;
|
||||
constructor({ helpDisplay, }: {
|
||||
helpDisplay: HelpDisplay;
|
||||
});
|
||||
run<T extends AnyCommand>(command: T, ...args: Parameters<T['run']>): ReturnType<T['run']> | undefined;
|
||||
}
|
||||
18
node_modules/astro/dist/cli/infra/cli-command-runner.js
generated
vendored
Normal file
18
node_modules/astro/dist/cli/infra/cli-command-runner.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
class CliCommandRunner {
|
||||
#helpDisplay;
|
||||
constructor({
|
||||
helpDisplay
|
||||
}) {
|
||||
this.#helpDisplay = helpDisplay;
|
||||
}
|
||||
run(command, ...args) {
|
||||
if (this.#helpDisplay.shouldFire()) {
|
||||
this.#helpDisplay.show(command.help);
|
||||
return;
|
||||
}
|
||||
return command.run(...args);
|
||||
}
|
||||
}
|
||||
export {
|
||||
CliCommandRunner
|
||||
};
|
||||
15
node_modules/astro/dist/cli/infra/logger-help-display.d.ts
generated
vendored
Normal file
15
node_modules/astro/dist/cli/infra/logger-help-display.d.ts
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
import type { Logger } from '../../core/logger/core.js';
|
||||
import type { AstroVersionProvider, HelpDisplay, TextStyler } from '../definitions.js';
|
||||
import type { HelpPayload } from '../domain/help-payload.js';
|
||||
import type { Flags } from '../flags.js';
|
||||
export declare class LoggerHelpDisplay implements HelpDisplay {
|
||||
#private;
|
||||
constructor({ logger, textStyler, astroVersionProvider, flags, }: {
|
||||
logger: Logger;
|
||||
textStyler: TextStyler;
|
||||
astroVersionProvider: AstroVersionProvider;
|
||||
flags: Flags;
|
||||
});
|
||||
shouldFire(): boolean;
|
||||
show({ commandName, description, headline, tables, usage }: HelpPayload): void;
|
||||
}
|
||||
71
node_modules/astro/dist/cli/infra/logger-help-display.js
generated
vendored
Normal file
71
node_modules/astro/dist/cli/infra/logger-help-display.js
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
import { formatVersion } from "../utils/format-version.js";
|
||||
class LoggerHelpDisplay {
|
||||
#logger;
|
||||
#textStyler;
|
||||
#astroVersionProvider;
|
||||
// TODO: find something better
|
||||
#flags;
|
||||
constructor({
|
||||
logger,
|
||||
textStyler,
|
||||
astroVersionProvider,
|
||||
flags
|
||||
}) {
|
||||
this.#logger = logger;
|
||||
this.#textStyler = textStyler;
|
||||
this.#astroVersionProvider = astroVersionProvider;
|
||||
this.#flags = flags;
|
||||
}
|
||||
shouldFire() {
|
||||
return !!(this.#flags.help || this.#flags.h);
|
||||
}
|
||||
show({ commandName, description, headline, tables, usage }) {
|
||||
const linebreak = () => "";
|
||||
const title = (label) => ` ${this.#textStyler.bgWhite(this.#textStyler.black(` ${label} `))}`;
|
||||
const table = (rows, { padding }) => {
|
||||
const split = process.stdout.columns < 60;
|
||||
let raw = "";
|
||||
for (const row of rows) {
|
||||
if (split) {
|
||||
raw += ` ${row[0]}
|
||||
`;
|
||||
} else {
|
||||
raw += `${`${row[0]}`.padStart(padding)}`;
|
||||
}
|
||||
raw += " " + this.#textStyler.dim(row[1]) + "\n";
|
||||
}
|
||||
return raw.slice(0, -1);
|
||||
};
|
||||
let message = [];
|
||||
if (headline) {
|
||||
message.push(
|
||||
linebreak(),
|
||||
`${formatVersion({ name: commandName, textStyler: this.#textStyler, astroVersionProvider: this.#astroVersionProvider })} ${headline}`
|
||||
);
|
||||
}
|
||||
if (usage) {
|
||||
message.push(
|
||||
linebreak(),
|
||||
` ${this.#textStyler.green(commandName)} ${this.#textStyler.bold(usage)}`
|
||||
);
|
||||
}
|
||||
if (tables) {
|
||||
let calculateTablePadding2 = function(rows) {
|
||||
return rows.reduce((val, [first]) => Math.max(val, first.length), 0) + 2;
|
||||
};
|
||||
var calculateTablePadding = calculateTablePadding2;
|
||||
const tableEntries = Object.entries(tables);
|
||||
const padding = Math.max(...tableEntries.map(([, rows]) => calculateTablePadding2(rows)));
|
||||
for (const [tableTitle, tableRows] of tableEntries) {
|
||||
message.push(linebreak(), title(tableTitle), table(tableRows, { padding }));
|
||||
}
|
||||
}
|
||||
if (description) {
|
||||
message.push(linebreak(), `${description}`);
|
||||
}
|
||||
this.#logger.info("SKIP_FORMAT", message.join("\n") + "\n");
|
||||
}
|
||||
}
|
||||
export {
|
||||
LoggerHelpDisplay
|
||||
};
|
||||
9
node_modules/astro/dist/cli/infra/passthrough-text-styler.d.ts
generated
vendored
Normal file
9
node_modules/astro/dist/cli/infra/passthrough-text-styler.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import type { TextStyler } from '../definitions.js';
|
||||
export declare class PassthroughTextStyler implements TextStyler {
|
||||
bgWhite(msg: string): string;
|
||||
black(msg: string): string;
|
||||
dim(msg: string): string;
|
||||
green(msg: string): string;
|
||||
bold(msg: string): string;
|
||||
bgGreen(msg: string): string;
|
||||
}
|
||||
23
node_modules/astro/dist/cli/infra/passthrough-text-styler.js
generated
vendored
Normal file
23
node_modules/astro/dist/cli/infra/passthrough-text-styler.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
class PassthroughTextStyler {
|
||||
bgWhite(msg) {
|
||||
return msg;
|
||||
}
|
||||
black(msg) {
|
||||
return msg;
|
||||
}
|
||||
dim(msg) {
|
||||
return msg;
|
||||
}
|
||||
green(msg) {
|
||||
return msg;
|
||||
}
|
||||
bold(msg) {
|
||||
return msg;
|
||||
}
|
||||
bgGreen(msg) {
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
export {
|
||||
PassthroughTextStyler
|
||||
};
|
||||
2
node_modules/astro/dist/cli/infra/piccolore-text-styler.d.ts
generated
vendored
Normal file
2
node_modules/astro/dist/cli/infra/piccolore-text-styler.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import type { TextStyler } from '../definitions.js';
|
||||
export declare const piccoloreTextStyler: TextStyler;
|
||||
5
node_modules/astro/dist/cli/infra/piccolore-text-styler.js
generated
vendored
Normal file
5
node_modules/astro/dist/cli/infra/piccolore-text-styler.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import colors from "piccolore";
|
||||
const piccoloreTextStyler = colors;
|
||||
export {
|
||||
piccoloreTextStyler
|
||||
};
|
||||
6
node_modules/astro/dist/cli/infra/process-operating-system-provider.d.ts
generated
vendored
Normal file
6
node_modules/astro/dist/cli/infra/process-operating-system-provider.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import type { OperatingSystemProvider } from '../definitions.js';
|
||||
export declare class ProcessOperatingSystemProvider implements OperatingSystemProvider {
|
||||
#private;
|
||||
readonly name: NodeJS.Platform;
|
||||
readonly displayName: string;
|
||||
}
|
||||
12
node_modules/astro/dist/cli/infra/process-operating-system-provider.js
generated
vendored
Normal file
12
node_modules/astro/dist/cli/infra/process-operating-system-provider.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
class ProcessOperatingSystemProvider {
|
||||
#platformToOs = {
|
||||
darwin: "macOS",
|
||||
win32: "Windows",
|
||||
linux: "Linux"
|
||||
};
|
||||
name = process.platform;
|
||||
displayName = `${this.#platformToOs[this.name] ?? this.name} (${process.arch})`;
|
||||
}
|
||||
export {
|
||||
ProcessOperatingSystemProvider
|
||||
};
|
||||
6
node_modules/astro/dist/cli/infra/tinyexec-command-executor.d.ts
generated
vendored
Normal file
6
node_modules/astro/dist/cli/infra/tinyexec-command-executor.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import type { CommandExecutor, CommandExecutorOptions } from '../definitions.js';
|
||||
export declare class TinyexecCommandExecutor implements CommandExecutor {
|
||||
execute(command: string, args?: Array<string>, options?: CommandExecutorOptions): Promise<{
|
||||
stdout: string;
|
||||
}>;
|
||||
}
|
||||
34
node_modules/astro/dist/cli/infra/tinyexec-command-executor.js
generated
vendored
Normal file
34
node_modules/astro/dist/cli/infra/tinyexec-command-executor.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
import { NonZeroExitError, x } from "tinyexec";
|
||||
class TinyexecCommandExecutor {
|
||||
async execute(command, args, options) {
|
||||
const proc = x(command, args, {
|
||||
throwOnError: true,
|
||||
nodeOptions: {
|
||||
cwd: options?.cwd,
|
||||
env: options?.env,
|
||||
shell: options?.shell,
|
||||
stdio: options?.stdio
|
||||
}
|
||||
});
|
||||
if (options?.input) {
|
||||
proc.process?.stdin?.end(options.input);
|
||||
}
|
||||
return await proc.then(
|
||||
(o) => o,
|
||||
(e) => {
|
||||
if (e instanceof NonZeroExitError) {
|
||||
const fullCommand = args?.length ? `${command} ${args.map((a) => a.includes(" ") ? `"${a}"` : a).join(" ")}` : command;
|
||||
const message = `The command \`${fullCommand}\` exited with code ${e.exitCode}`;
|
||||
const newError = new Error(message, e.cause ? { cause: e.cause } : void 0);
|
||||
newError.stderr = e.output?.stderr;
|
||||
newError.stdout = e.output?.stdout;
|
||||
throw newError;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
export {
|
||||
TinyexecCommandExecutor
|
||||
};
|
||||
10
node_modules/astro/dist/cli/install-package.d.ts
generated
vendored
Normal file
10
node_modules/astro/dist/cli/install-package.d.ts
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import type { Logger } from '../core/logger/core.js';
|
||||
type GetPackageOptions = {
|
||||
skipAsk?: boolean;
|
||||
optional?: boolean;
|
||||
cwd?: string;
|
||||
};
|
||||
export declare function getPackage<T>(packageName: string, logger: Logger, options: GetPackageOptions, otherDeps?: string[]): Promise<T | undefined>;
|
||||
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 {};
|
||||
142
node_modules/astro/dist/cli/install-package.js
generated
vendored
Normal file
142
node_modules/astro/dist/cli/install-package.js
generated
vendored
Normal file
@@ -0,0 +1,142 @@
|
||||
import { createRequire } from "node:module";
|
||||
import boxen from "boxen";
|
||||
import ci from "ci-info";
|
||||
import { detect, resolveCommand } from "package-manager-detector";
|
||||
import colors from "piccolore";
|
||||
import prompts from "prompts";
|
||||
import yoctoSpinner from "yocto-spinner";
|
||||
import { exec } from "./exec.js";
|
||||
const require2 = createRequire(import.meta.url);
|
||||
const { bold, cyan, dim, magenta } = colors;
|
||||
async function getPackage(packageName, logger, options, otherDeps = []) {
|
||||
try {
|
||||
require2.resolve(packageName, { paths: [options.cwd ?? process.cwd()] });
|
||||
const packageImport = await import(packageName);
|
||||
return packageImport;
|
||||
} catch {
|
||||
if (options.optional) return void 0;
|
||||
let message = `To continue, Astro requires the following dependency to be installed: ${bold(
|
||||
packageName
|
||||
)}.`;
|
||||
if (ci.isCI) {
|
||||
message += ` Packages cannot be installed automatically in CI environments.`;
|
||||
}
|
||||
logger.info("SKIP_FORMAT", message);
|
||||
if (ci.isCI) {
|
||||
return void 0;
|
||||
}
|
||||
const result = await installPackage([packageName, ...otherDeps], options, logger);
|
||||
if (result) {
|
||||
const packageImport = await import(packageName);
|
||||
return packageImport;
|
||||
} else {
|
||||
return void 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
async function installPackage(packageNames, options, logger) {
|
||||
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") {
|
||||
packageNames = packageNames.map((name) => `npm:${name}`);
|
||||
}
|
||||
const coloredOutput = `${bold(installCommand.command)} ${installCommand.args.join(" ")} ${cyan(packageNames.join(" "))}`;
|
||||
const message = `
|
||||
${boxen(coloredOutput, {
|
||||
margin: 0.5,
|
||||
padding: 0.5,
|
||||
borderStyle: "round"
|
||||
})}
|
||||
`;
|
||||
logger.info(
|
||||
"SKIP_FORMAT",
|
||||
`
|
||||
${magenta("Astro will run the following command:")}
|
||||
${dim(
|
||||
"If you skip this step, you can always run it yourself later"
|
||||
)}
|
||||
${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: void 0 }
|
||||
}
|
||||
});
|
||||
spinner.success();
|
||||
return true;
|
||||
} catch (err) {
|
||||
logger.debug("add", "Error installing dependencies", err);
|
||||
spinner.error();
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
async function fetchPackageJson(scope, name, tag) {
|
||||
const packageName = `${scope ? `${scope}/` : ""}${name}`;
|
||||
const registry = await getRegistry();
|
||||
const res = await fetch(`${registry}/${packageName}/${tag}`);
|
||||
if (res.status >= 200 && res.status < 300) {
|
||||
return await res.json();
|
||||
} else if (res.status === 404) {
|
||||
return new Error();
|
||||
} else {
|
||||
return new Error(`Failed to fetch ${registry}/${packageName}/${tag} - GET ${res.status}`);
|
||||
}
|
||||
}
|
||||
async function fetchPackageVersions(packageName) {
|
||||
const registry = await getRegistry();
|
||||
const res = await fetch(`${registry}/${packageName}`, {
|
||||
headers: { accept: "application/vnd.npm.install-v1+json" }
|
||||
});
|
||||
if (res.status >= 200 && res.status < 300) {
|
||||
return await res.json().then((data) => Object.keys(data.versions));
|
||||
} else if (res.status === 404) {
|
||||
return new Error();
|
||||
} else {
|
||||
return new Error(`Failed to fetch ${registry}/${packageName} - GET ${res.status}`);
|
||||
}
|
||||
}
|
||||
let _registry;
|
||||
async function getRegistry() {
|
||||
if (_registry) return _registry;
|
||||
const fallback = "https://registry.npmjs.org";
|
||||
const packageManager = (await detect())?.name || "npm";
|
||||
try {
|
||||
const { stdout } = await exec(packageManager, ["config", "get", "registry"]);
|
||||
_registry = stdout.trim()?.replace(/\/$/, "") || fallback;
|
||||
if (!new URL(_registry).host) _registry = fallback;
|
||||
} catch {
|
||||
_registry = fallback;
|
||||
}
|
||||
return _registry;
|
||||
}
|
||||
export {
|
||||
fetchPackageJson,
|
||||
fetchPackageVersions,
|
||||
getPackage
|
||||
};
|
||||
6
node_modules/astro/dist/cli/preferences/index.d.ts
generated
vendored
Normal file
6
node_modules/astro/dist/cli/preferences/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import { type Flags } from '../flags.js';
|
||||
interface PreferencesOptions {
|
||||
flags: Flags;
|
||||
}
|
||||
export declare function preferences(subcommand: string, key: string, value: string | undefined, { flags }: PreferencesOptions): Promise<number>;
|
||||
export {};
|
||||
297
node_modules/astro/dist/cli/preferences/index.js
generated
vendored
Normal file
297
node_modules/astro/dist/cli/preferences/index.js
generated
vendored
Normal file
@@ -0,0 +1,297 @@
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { formatWithOptions } from "node:util";
|
||||
import dlv from "dlv";
|
||||
import { flattie } from "flattie";
|
||||
import colors from "piccolore";
|
||||
import { resolveConfig } from "../../core/config/config.js";
|
||||
import { createSettings } from "../../core/config/settings.js";
|
||||
import { collectErrorMetadata } from "../../core/errors/dev/utils.js";
|
||||
import * as msg from "../../core/messages.js";
|
||||
import { DEFAULT_PREFERENCES } from "../../preferences/defaults.js";
|
||||
import { coerce, isValidKey } from "../../preferences/index.js";
|
||||
import { createLoggerFromFlags, flagsToAstroInlineConfig } from "../flags.js";
|
||||
const { bgGreen, black, bold, dim, yellow } = colors;
|
||||
const PREFERENCES_SUBCOMMANDS = [
|
||||
"get",
|
||||
"set",
|
||||
"enable",
|
||||
"disable",
|
||||
"delete",
|
||||
"reset",
|
||||
"list"
|
||||
];
|
||||
function isValidSubcommand(subcommand) {
|
||||
return PREFERENCES_SUBCOMMANDS.includes(subcommand);
|
||||
}
|
||||
async function preferences(subcommand, key, value, { flags }) {
|
||||
if (!isValidSubcommand(subcommand) || flags?.help || flags?.h) {
|
||||
msg.printHelp({
|
||||
commandName: "astro preferences",
|
||||
usage: "[command]",
|
||||
tables: {
|
||||
Commands: [
|
||||
["list", "Pretty print all current preferences"],
|
||||
["list --json", "Log all current preferences as a JSON object"],
|
||||
["get [key]", "Log current preference value"],
|
||||
["set [key] [value]", "Update preference value"],
|
||||
["reset [key]", "Reset preference value to default"],
|
||||
["enable [key]", "Set a boolean preference to true"],
|
||||
["disable [key]", "Set a boolean preference to false"]
|
||||
],
|
||||
Flags: [
|
||||
[
|
||||
"--global",
|
||||
"Scope command to global preferences (all Astro projects) rather than the current project"
|
||||
]
|
||||
]
|
||||
}
|
||||
});
|
||||
return 0;
|
||||
}
|
||||
const inlineConfig = flagsToAstroInlineConfig(flags);
|
||||
const logger = createLoggerFromFlags(flags);
|
||||
const { astroConfig } = await resolveConfig(inlineConfig ?? {}, "dev");
|
||||
const settings = await createSettings(astroConfig, fileURLToPath(astroConfig.root));
|
||||
const opts = {
|
||||
location: flags.global ? "global" : void 0,
|
||||
json: !!flags.json
|
||||
};
|
||||
if (subcommand === "list") {
|
||||
return listPreferences(settings, opts);
|
||||
}
|
||||
if (subcommand === "enable" || subcommand === "disable") {
|
||||
key = `${key}.enabled`;
|
||||
}
|
||||
if (!isValidKey(key)) {
|
||||
logger.error("preferences", `Unknown preference "${key}"
|
||||
`);
|
||||
return 1;
|
||||
}
|
||||
if (subcommand === "set" && value === void 0) {
|
||||
const type = typeof dlv(DEFAULT_PREFERENCES, key);
|
||||
console.error(
|
||||
msg.formatErrorMessage(
|
||||
collectErrorMetadata(new Error(`Please provide a ${type} value for "${key}"`)),
|
||||
true
|
||||
)
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
switch (subcommand) {
|
||||
case "get":
|
||||
return getPreference(settings, key, opts);
|
||||
case "set":
|
||||
return setPreference(settings, key, value, opts);
|
||||
case "reset":
|
||||
case "delete":
|
||||
return resetPreference(settings, key, opts);
|
||||
case "enable":
|
||||
return enablePreference(settings, key, opts);
|
||||
case "disable":
|
||||
return disablePreference(settings, key, opts);
|
||||
}
|
||||
}
|
||||
async function getPreference(settings, key, { location = "project" }) {
|
||||
try {
|
||||
let value = await settings.preferences.get(key, { location });
|
||||
if (value && typeof value === "object" && !Array.isArray(value)) {
|
||||
if (Object.keys(value).length === 0) {
|
||||
value = dlv(DEFAULT_PREFERENCES, key);
|
||||
console.log(msg.preferenceDefaultIntro(key));
|
||||
}
|
||||
prettyPrint({ [key]: value });
|
||||
return 0;
|
||||
}
|
||||
if (value === void 0) {
|
||||
const defaultValue = await settings.preferences.get(key);
|
||||
console.log(msg.preferenceDefault(key, defaultValue));
|
||||
return 0;
|
||||
}
|
||||
console.log(msg.preferenceGet(key, value));
|
||||
return 0;
|
||||
} catch {
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
async function setPreference(settings, key, value, { location }) {
|
||||
try {
|
||||
const defaultType = typeof dlv(DEFAULT_PREFERENCES, key);
|
||||
if (typeof coerce(key, value) !== defaultType) {
|
||||
throw new Error(`${key} expects a "${defaultType}" value!`);
|
||||
}
|
||||
await settings.preferences.set(key, coerce(key, value), { location });
|
||||
console.log(msg.preferenceSet(key, value));
|
||||
return 0;
|
||||
} catch (e) {
|
||||
if (e instanceof Error) {
|
||||
console.error(msg.formatErrorMessage(collectErrorMetadata(e), true));
|
||||
return 1;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
async function enablePreference(settings, key, { location }) {
|
||||
try {
|
||||
await settings.preferences.set(key, true, { location });
|
||||
console.log(msg.preferenceEnabled(key.replace(".enabled", "")));
|
||||
return 0;
|
||||
} catch {
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
async function disablePreference(settings, key, { location }) {
|
||||
try {
|
||||
await settings.preferences.set(key, false, { location });
|
||||
console.log(msg.preferenceDisabled(key.replace(".enabled", "")));
|
||||
return 0;
|
||||
} catch {
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
async function resetPreference(settings, key, { location }) {
|
||||
try {
|
||||
await settings.preferences.set(key, void 0, { location });
|
||||
console.log(msg.preferenceReset(key));
|
||||
return 0;
|
||||
} catch {
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
function annotate(flat, annotation) {
|
||||
return Object.fromEntries(
|
||||
Object.entries(flat).map(([key, value]) => [key, { annotation, value }])
|
||||
);
|
||||
}
|
||||
function userValues(flatDefault, flatProject, flatGlobal) {
|
||||
const result = {};
|
||||
for (const key of Object.keys(flatDefault)) {
|
||||
if (key in flatProject) {
|
||||
result[key] = {
|
||||
value: flatProject[key],
|
||||
annotation: ""
|
||||
};
|
||||
if (key in flatGlobal) {
|
||||
result[key].annotation += ` (also modified globally)`;
|
||||
}
|
||||
} else if (key in flatGlobal) {
|
||||
result[key] = { value: flatGlobal[key], annotation: "(global)" };
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
async function listPreferences(settings, { location, json }) {
|
||||
if (json) {
|
||||
const resolved = await settings.preferences.getAll();
|
||||
console.log(JSON.stringify(resolved, null, 2));
|
||||
return 0;
|
||||
}
|
||||
const { global, project, fromAstroConfig, defaults } = await settings.preferences.list({
|
||||
location
|
||||
});
|
||||
const flatProject = flattie(project);
|
||||
const flatGlobal = flattie(global);
|
||||
const flatDefault = flattie(defaults);
|
||||
const flatUser = userValues(flatDefault, flatProject, flatGlobal);
|
||||
const userKeys = Object.keys(flatUser);
|
||||
if (userKeys.length > 0) {
|
||||
const badge = bgGreen(black(` Your Preferences `));
|
||||
const table = formatTable(flatUser, ["Preference", "Value"]);
|
||||
console.log(["", badge, table].join("\n"));
|
||||
} else {
|
||||
const badge = bgGreen(black(` Your Preferences `));
|
||||
const message = dim("No preferences set");
|
||||
console.log(["", badge, "", message].join("\n"));
|
||||
}
|
||||
const flatUnset = annotate(Object.assign({}, flatDefault), "");
|
||||
for (const key of userKeys) {
|
||||
delete flatUnset[key];
|
||||
}
|
||||
const unsetKeys = Object.keys(flatUnset);
|
||||
if (unsetKeys.length > 0) {
|
||||
const badge = bgGreen(black(` Default Preferences `));
|
||||
const table = formatTable(flatUnset, ["Preference", "Value"]);
|
||||
console.log(["", badge, table].join("\n"));
|
||||
} else {
|
||||
const badge = bgGreen(black(` Default Preferences `));
|
||||
const message = dim("All preferences have been set");
|
||||
console.log(["", badge, "", message].join("\n"));
|
||||
}
|
||||
if (fromAstroConfig.devToolbar?.enabled === false && flatUser["devToolbar.enabled"]?.value !== false) {
|
||||
console.log(
|
||||
yellow(
|
||||
"The dev toolbar is currently disabled. To enable it, set devToolbar: {enabled: true} in your astroConfig file."
|
||||
)
|
||||
);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
function prettyPrint(value) {
|
||||
const flattened = flattie(value);
|
||||
const table = formatTable(flattened, ["Preference", "Value"]);
|
||||
console.log(table);
|
||||
}
|
||||
const chars = {
|
||||
h: "\u2500",
|
||||
hThick: "\u2501",
|
||||
hThickCross: "\u253F",
|
||||
v: "\u2502",
|
||||
vRight: "\u251C",
|
||||
vRightThick: "\u251D",
|
||||
vLeft: "\u2524",
|
||||
vLeftThick: "\u2525",
|
||||
hTop: "\u2534",
|
||||
hBottom: "\u252C",
|
||||
topLeft: "\u256D",
|
||||
topRight: "\u256E",
|
||||
bottomLeft: "\u2570",
|
||||
bottomRight: "\u256F"
|
||||
};
|
||||
function annotatedFormat(mv) {
|
||||
return mv.annotation ? `${mv.value} ${mv.annotation}` : mv.value.toString();
|
||||
}
|
||||
function formatAnnotated(mv, style = (v) => v.toString()) {
|
||||
return mv.annotation ? `${style(String(mv.value))} ${dim(mv.annotation)}` : style(String(mv.value));
|
||||
}
|
||||
function formatTable(object, columnLabels) {
|
||||
const [colA, colB] = columnLabels;
|
||||
const colALength = [colA, ...Object.keys(object)].reduce(longest, 0) + 3;
|
||||
const colBLength = [colB, ...Object.values(object).map(annotatedFormat)].reduce(longest, 0) + 3;
|
||||
function formatRow(_i, a, b, style = (v) => v.toString()) {
|
||||
return `${dim(chars.v)} ${style(a)} ${space(colALength - a.length - 2)} ${dim(
|
||||
chars.v
|
||||
)} ${formatAnnotated(b, style)} ${space(colBLength - annotatedFormat(b).length - 3)} ${dim(
|
||||
chars.v
|
||||
)}`;
|
||||
}
|
||||
const top = dim(
|
||||
`${chars.topLeft}${chars.h.repeat(colALength + 1)}${chars.hBottom}${chars.h.repeat(
|
||||
colBLength
|
||||
)}${chars.topRight}`
|
||||
);
|
||||
const bottom = dim(
|
||||
`${chars.bottomLeft}${chars.h.repeat(colALength + 1)}${chars.hTop}${chars.h.repeat(
|
||||
colBLength
|
||||
)}${chars.bottomRight}`
|
||||
);
|
||||
const divider = dim(
|
||||
`${chars.vRightThick}${chars.hThick.repeat(colALength + 1)}${chars.hThickCross}${chars.hThick.repeat(colBLength)}${chars.vLeftThick}`
|
||||
);
|
||||
const rows = [top, formatRow(-1, colA, { value: colB, annotation: "" }, bold), divider];
|
||||
let i = 0;
|
||||
for (const [key, value] of Object.entries(object)) {
|
||||
rows.push(formatRow(i, key, value, (v) => formatWithOptions({ colors: true }, v)));
|
||||
i++;
|
||||
}
|
||||
rows.push(bottom);
|
||||
return rows.join("\n");
|
||||
}
|
||||
function space(len) {
|
||||
return " ".repeat(len);
|
||||
}
|
||||
const longest = (a, b) => {
|
||||
const { length: len } = b.toString();
|
||||
return a > len ? a : len;
|
||||
};
|
||||
export {
|
||||
preferences
|
||||
};
|
||||
6
node_modules/astro/dist/cli/preview/index.d.ts
generated
vendored
Normal file
6
node_modules/astro/dist/cli/preview/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import { type Flags } from '../flags.js';
|
||||
interface PreviewOptions {
|
||||
flags: Flags;
|
||||
}
|
||||
export declare function preview({ flags }: PreviewOptions): Promise<import("../../index.js").PreviewServer | undefined>;
|
||||
export {};
|
||||
34
node_modules/astro/dist/cli/preview/index.js
generated
vendored
Normal file
34
node_modules/astro/dist/cli/preview/index.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
import colors from "piccolore";
|
||||
import { printHelp } from "../../core/messages.js";
|
||||
import previewServer from "../../core/preview/index.js";
|
||||
import { flagsToAstroInlineConfig } from "../flags.js";
|
||||
async function preview({ flags }) {
|
||||
if (flags?.help || flags?.h) {
|
||||
printHelp({
|
||||
commandName: "astro preview",
|
||||
usage: "[...flags]",
|
||||
tables: {
|
||||
Flags: [
|
||||
["--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"],
|
||||
[
|
||||
"--allowed-hosts",
|
||||
"Specify a comma-separated list of allowed hosts or allow any hostname."
|
||||
],
|
||||
["--help (-h)", "See all available flags."]
|
||||
]
|
||||
},
|
||||
description: `Starts a local server to serve your static dist/ directory. Check ${colors.cyan(
|
||||
"https://docs.astro.build/en/reference/cli-reference/#astro-preview"
|
||||
)} for more information.`
|
||||
});
|
||||
return;
|
||||
}
|
||||
const inlineConfig = flagsToAstroInlineConfig(flags);
|
||||
return await previewServer(inlineConfig);
|
||||
}
|
||||
export {
|
||||
preview
|
||||
};
|
||||
6
node_modules/astro/dist/cli/sync/index.d.ts
generated
vendored
Normal file
6
node_modules/astro/dist/cli/sync/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import { type Flags } from '../flags.js';
|
||||
interface SyncOptions {
|
||||
flags: Flags;
|
||||
}
|
||||
export declare function sync({ flags }: SyncOptions): Promise<0 | undefined>;
|
||||
export {};
|
||||
23
node_modules/astro/dist/cli/sync/index.js
generated
vendored
Normal file
23
node_modules/astro/dist/cli/sync/index.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
import { printHelp } from "../../core/messages.js";
|
||||
import _sync from "../../core/sync/index.js";
|
||||
import { flagsToAstroInlineConfig } from "../flags.js";
|
||||
async function sync({ flags }) {
|
||||
if (flags?.help || flags?.h) {
|
||||
printHelp({
|
||||
commandName: "astro sync",
|
||||
usage: "[...flags]",
|
||||
tables: {
|
||||
Flags: [
|
||||
["--force", "Clear the content layer cache, forcing a full rebuild."],
|
||||
["--help (-h)", "See all available flags."]
|
||||
]
|
||||
},
|
||||
description: `Generates TypeScript types for all Astro modules.`
|
||||
});
|
||||
return 0;
|
||||
}
|
||||
await _sync(flagsToAstroInlineConfig(flags), { telemetry: true });
|
||||
}
|
||||
export {
|
||||
sync
|
||||
};
|
||||
7
node_modules/astro/dist/cli/telemetry/index.d.ts
generated
vendored
Normal file
7
node_modules/astro/dist/cli/telemetry/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import { type Flags } from '../flags.js';
|
||||
interface TelemetryOptions {
|
||||
flags: Flags;
|
||||
}
|
||||
export declare function notify(): Promise<void>;
|
||||
export declare function update(subcommand: string, { flags }: TelemetryOptions): Promise<void>;
|
||||
export {};
|
||||
48
node_modules/astro/dist/cli/telemetry/index.js
generated
vendored
Normal file
48
node_modules/astro/dist/cli/telemetry/index.js
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
import * as msg from "../../core/messages.js";
|
||||
import { telemetry } from "../../events/index.js";
|
||||
import { createLoggerFromFlags } from "../flags.js";
|
||||
async function notify() {
|
||||
await telemetry.notify(() => {
|
||||
console.log(msg.telemetryNotice() + "\n");
|
||||
return true;
|
||||
});
|
||||
}
|
||||
async function update(subcommand, { flags }) {
|
||||
const isValid = ["enable", "disable", "reset"].includes(subcommand);
|
||||
const logger = createLoggerFromFlags(flags);
|
||||
if (flags.help || flags.h || !isValid) {
|
||||
msg.printHelp({
|
||||
commandName: "astro telemetry",
|
||||
usage: "[command]",
|
||||
tables: {
|
||||
Commands: [
|
||||
["enable", "Enable anonymous data collection."],
|
||||
["disable", "Disable anonymous data collection."],
|
||||
["reset", "Reset anonymous data collection settings."]
|
||||
]
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
switch (subcommand) {
|
||||
case "enable": {
|
||||
telemetry.setEnabled(true);
|
||||
logger.info("SKIP_FORMAT", msg.telemetryEnabled());
|
||||
return;
|
||||
}
|
||||
case "disable": {
|
||||
telemetry.setEnabled(false);
|
||||
logger.info("SKIP_FORMAT", msg.telemetryDisabled());
|
||||
return;
|
||||
}
|
||||
case "reset": {
|
||||
telemetry.clear();
|
||||
logger.info("SKIP_FORMAT", msg.telemetryReset());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
export {
|
||||
notify,
|
||||
update
|
||||
};
|
||||
2
node_modules/astro/dist/cli/throw-and-exit.d.ts
generated
vendored
Normal file
2
node_modules/astro/dist/cli/throw-and-exit.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/** Display error and exit */
|
||||
export declare function throwAndExit(cmd: string, err: unknown): Promise<void>;
|
||||
25
node_modules/astro/dist/cli/throw-and-exit.js
generated
vendored
Normal file
25
node_modules/astro/dist/cli/throw-and-exit.js
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
import { collectErrorMetadata } from "../core/errors/dev/index.js";
|
||||
import { isAstroConfigZodError } from "../core/errors/errors.js";
|
||||
import { createSafeError } from "../core/errors/index.js";
|
||||
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)) {
|
||||
process.exit(1);
|
||||
}
|
||||
let telemetryPromise;
|
||||
let errorMessage;
|
||||
function exitWithErrorMessage() {
|
||||
console.error(errorMessage);
|
||||
process.exit(1);
|
||||
}
|
||||
const errorWithMetadata = collectErrorMetadata(createSafeError(err));
|
||||
telemetryPromise = telemetry.record(eventError({ cmd, err: errorWithMetadata, isFatal: true }));
|
||||
errorMessage = formatErrorMessage(errorWithMetadata, true);
|
||||
setTimeout(exitWithErrorMessage, 400);
|
||||
await telemetryPromise.catch((err2) => debug("telemetry", `record() error: ${err2.message}`)).then(exitWithErrorMessage);
|
||||
}
|
||||
export {
|
||||
throwAndExit
|
||||
};
|
||||
8
node_modules/astro/dist/cli/utils/format-version.d.ts
generated
vendored
Normal file
8
node_modules/astro/dist/cli/utils/format-version.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import type { AstroVersionProvider, TextStyler } from '../definitions.js';
|
||||
interface Options {
|
||||
name: string;
|
||||
textStyler: TextStyler;
|
||||
astroVersionProvider: AstroVersionProvider;
|
||||
}
|
||||
export declare function formatVersion({ name, textStyler, astroVersionProvider }: Options): string;
|
||||
export {};
|
||||
8
node_modules/astro/dist/cli/utils/format-version.js
generated
vendored
Normal file
8
node_modules/astro/dist/cli/utils/format-version.js
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
function formatVersion({ name, textStyler, astroVersionProvider }) {
|
||||
return ` ${textStyler.bgGreen(textStyler.black(` ${name} `))} ${textStyler.green(
|
||||
`v${astroVersionProvider.version}`
|
||||
)}`;
|
||||
}
|
||||
export {
|
||||
formatVersion
|
||||
};
|
||||
Reference in New Issue
Block a user