Amplify Prompts Utility
amplify-prompts is an internal utility package within the AWS Amplify CLI monorepo, providing standardized terminal I/O functions for interactive command-line experiences. It is currently at version 2.6.8, with the broader Amplify CLI ecosystem seeing frequent releases (e.g., v14.x.x). This package is not typically intended for direct consumption by end-user applications but is crucial for developers extending or building upon the Amplify CLI itself. It offers a consistent API for various prompting needs like text input, confirmations, and selections, ensuring a uniform user experience across different Amplify CLI commands and custom categories. It ships with TypeScript types, facilitating robust development for CLI contributors. Its release cadence is tied to the broader Amplify CLI releases, making it a stable component within that ecosystem.
Common errors
-
TypeError: (0, amplify_prompts__WEBPACK_IMPORTED_MODULE_0__.input) is not a function
cause Incorrectly importing named exports, often due to a default import when none exists, or incorrect pathing in a bundler context.fixEnsure you are using named imports with curly braces: `import { input } from 'amplify-prompts';`. Verify your bundler configuration correctly handles module resolution. -
Process hangs, waiting for input indefinitely in CI/CD pipeline.
cause An interactive prompt function (e.g., `input`, `confirm`, `select`) was invoked in a non-interactive environment without a mechanism to provide input.fixReview the calling Amplify CLI command for options to provide non-interactive answers (e.g., `--yes`, `--force`). If directly using `amplify-prompts`, ensure logic bypasses interactive prompts when `process.stdout.isTTY` is false or use a mocking library for tests. -
Error: stdout is not a TTY
cause The prompt library detects that `process.stdout` is not connected to a terminal, which is necessary for interactive prompts to function correctly.fixThis is often an environmental issue when running in a debugger or an IDE's output window that doesn't fully simulate a TTY. Try running the script directly from your system's terminal.
Warnings
- gotcha The `amplify-prompts` package is primarily an internal utility of the AWS Amplify CLI. While it's published, direct consumption by end-user applications is generally not the intended use case. Its API might change more fluidly with CLI internal refactors.
- breaking Changes in underlying Node.js versions supported by the Amplify CLI can lead to unexpected behavior or incompatibilities with prompt rendering, especially concerning `stdin`/`stdout` handling.
- gotcha Running `amplify-prompts` in non-interactive environments (e.g., CI/CD pipelines) without providing default answers or mocking inputs will cause processes to hang indefinitely, awaiting user input.
- deprecated Older versions of the Amplify CLI or internal utilities might have relied on CommonJS (`require`) for module loading. Modern Amplify CLI development primarily uses ESM (`import`).
Install
-
npm install amplify-prompts -
yarn add amplify-prompts -
pnpm add amplify-prompts
Imports
- input
const { input } = require('amplify-prompts');import { input } from 'amplify-prompts'; - confirm
import confirm from 'amplify-prompts';
import { confirm } from 'amplify-prompts'; - select
import { Select } from 'amplify-prompts';import { select } from 'amplify-prompts';
Quickstart
import { input, confirm, select } from 'amplify-prompts';
async function runAmplifyPromptsDemo() {
console.log('Starting Amplify Prompts Demo...');
const projectName = await input('Enter your project name:');
console.log(`Project name entered: ${projectName}`);
const needsAuth = await confirm('Does your project require authentication?');
console.log(`Authentication required: ${needsAuth ? 'Yes' : 'No'}`);
if (needsAuth) {
const authType = await select(
'Select an authentication type:',
[
{ name: 'Email/Password', value: 'email_password' },
{ name: 'Social Login', value: 'social_login' },
{ name: 'API Key', value: 'api_key' }
]
);
console.log(`Authentication type selected: ${authType}`);
}
console.log('Amplify Prompts Demo finished.');
}
runAmplifyPromptsDemo().catch(console.error);