From 424ac56cf1851517210ca6a4c5909e21c7d4ce75 Mon Sep 17 00:00:00 2001 From: Matt Kane Date: Wed, 19 Nov 2025 11:33:09 +0000 Subject: [PATCH 1/2] feat: add hint about astro add --yes flag --- .changeset/eighty-cloths-sleep.md | 5 +++++ packages/astro/src/cli/add/index.ts | 30 +++++++++++++++++------------ 2 files changed, 23 insertions(+), 12 deletions(-) create mode 100644 .changeset/eighty-cloths-sleep.md diff --git a/.changeset/eighty-cloths-sleep.md b/.changeset/eighty-cloths-sleep.md new file mode 100644 index 000000000000..4b9231aaf7d4 --- /dev/null +++ b/.changeset/eighty-cloths-sleep.md @@ -0,0 +1,5 @@ +--- +'astro': minor +--- + +Add hint to use `--yes` flag with `astro add` diff --git a/packages/astro/src/cli/add/index.ts b/packages/astro/src/cli/add/index.ts index e44cfe29b021..da6ee9e7a113 100644 --- a/packages/astro/src/cli/add/index.ts +++ b/packages/astro/src/cli/add/index.ts @@ -157,7 +157,7 @@ export async function add(names: string[], { flags }: AddOptions) { 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); + const integrations = await validateIntegrations(integrationNames, flags, logger); let installResult = await tryToInstallIntegrations({ integrations, cwd, flags, logger }); const rootPath = resolveRoot(cwd); const root = pathToFileURL(rootPath); @@ -216,7 +216,7 @@ export async function add(names: string[], { flags }: AddOptions) { `\n ${magenta(`Astro will scaffold ${green('./wrangler.jsonc')}.`)}\n`, ); - if (await askToContinue({ flags })) { + if (await askToContinue({ flags, logger })) { const data = await getPackageJson(); await fs.writeFile( @@ -237,7 +237,7 @@ export async function add(names: string[], { flags }: AddOptions) { `\n ${magenta(`Astro will scaffold ${green('./public/.assetsignore')}.`)}\n`, ); - if (await askToContinue({ flags })) { + if (await askToContinue({ flags, logger })) { if (!existsSync(dir)) { await fs.mkdir(dir); } @@ -256,7 +256,7 @@ export async function add(names: string[], { flags }: AddOptions) { `\n ${magenta(`Astro will scaffold ${green('./src/styles/global.css')}.`)}\n`, ); - if (await askToContinue({ flags })) { + if (await askToContinue({ flags, logger })) { if (!existsSync(dir)) { await fs.mkdir(dir); } @@ -293,7 +293,7 @@ export async function add(names: string[], { flags }: AddOptions) { )}\n`, ); - if (await askToContinue({ flags })) { + 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' }), @@ -666,7 +666,7 @@ async function updateAstroConfig({ ); } - if (await askToContinue({ flags })) { + if (await askToContinue({ flags, logger })) { await fs.writeFile(fileURLToPath(configURL), output, { encoding: 'utf-8' }); logger.debug('add', `Updated astro config`); return UpdateResult.updated; @@ -770,7 +770,7 @@ async function tryToInstallIntegrations({ )}\n${message}`, ); - if (await askToContinue({ flags })) { + if (await askToContinue({ flags, logger })) { const spinner = yoctoSpinner({ text: 'Installing dependencies...' }).start(); try { await exec(installCommand.command, [...installCommand.args, ...installSpecifiers], { @@ -797,6 +797,7 @@ async function tryToInstallIntegrations({ async function validateIntegrations( integrations: string[], flags: yargsParser.Arguments, + logger: Logger, ): Promise { const spinner = yoctoSpinner({ text: 'Resolving packages...' }).start(); try { @@ -819,7 +820,7 @@ async function validateIntegrations( spinner.warning(yellow(firstPartyPkgCheck.message)); } spinner.warning(yellow(`${bold(integration)} is not an official Astro package.`)); - if (!(await askToContinue({ flags }))) { + if (!(await askToContinue({ flags, logger }))) { throw new Error( `No problem! Find our official integrations at ${cyan( 'https://astro.build/integrations', @@ -987,7 +988,7 @@ async function updateTSConfig( ); } - if (await askToContinue({ flags })) { + if (await askToContinue({ flags, logger })) { await fs.writeFile(inputConfig.tsconfigFile, output, { encoding: 'utf-8', }); @@ -1014,9 +1015,14 @@ function parseIntegrationName(spec: string) { return { scope, name, tag }; } -async function askToContinue({ flags }: { flags: Flags }): Promise { - if (flags.yes || flags.y) return true; +let hasHintedAboutYesFlag = false; +async function askToContinue({ flags, logger }: { flags: Flags, logger: Logger }): Promise { + 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', @@ -1078,7 +1084,7 @@ async function setupIntegrationConfig(opts: { 'SKIP_FORMAT', `\n ${magenta(`Astro will generate a minimal ${bold(opts.defaultConfigFile)} file.`)}\n`, ); - if (await askToContinue({ flags: opts.flags })) { + if (await askToContinue({ flags: opts.flags, logger })) { await fs.writeFile( fileURLToPath(new URL(opts.defaultConfigFile, opts.root)), opts.defaultConfigContent, From cd4a9b58de185280e629f6404c5f51ea86e67424 Mon Sep 17 00:00:00 2001 From: Florian Lefebvre Date: Wed, 19 Nov 2025 16:28:57 +0100 Subject: [PATCH 2/2] Update .changeset/eighty-cloths-sleep.md Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com> --- .changeset/eighty-cloths-sleep.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/eighty-cloths-sleep.md b/.changeset/eighty-cloths-sleep.md index 4b9231aaf7d4..850bc60d2641 100644 --- a/.changeset/eighty-cloths-sleep.md +++ b/.changeset/eighty-cloths-sleep.md @@ -2,4 +2,4 @@ 'astro': minor --- -Add hint to use `--yes` flag with `astro add` +Adds a hint for code agents to use the `--yes` flag to skip prompts when running `astro add`