Skip to content

fix(preset): use default enquirer import so interactive workspace creation works#898

Merged
cogwirrel merged 2 commits into
mainfrom
fix/preset-enquirer-interactive
Jul 7, 2026
Merged

fix(preset): use default enquirer import so interactive workspace creation works#898
cogwirrel merged 2 commits into
mainfrom
fix/preset-enquirer-interactive

Conversation

@nx-plugin-for-aws

Copy link
Copy Markdown
Collaborator

Reason for this change

Creating a workspace interactively (without --no-interactive) crashed:

 NX   enquirer.prompt is not a function
    at presetGenerator (.../@aws/nx-plugin/src/preset/generator.js:125:49)

import * as enquirer compiles to a native ESM namespace import since the plugin migrated to ESM (#853). enquirer is a CommonJS package whose prompt is assigned as a runtime static, which cjs-module-lexer can't surface as a named export — so enquirer.prompt was undefined. Under the old CommonJS output the same import * as compiled to require() and worked, so this regressed with the ESM migration.

Description of changes

  • Fix the crash: switch to a default import (import enquirer from 'enquirer'), for which enquirer.prompt resolves correctly.
  • Prevent a hang: guard the engagementId prompt on process.stdin.isTTY. create-nx-workspace runs the preset via exec, which gives it a data-less stdin pipe (the parent TTY is never forwarded across an exec boundary). Once the crash is fixed, prompting there would hang forever. With the guard, the prompt is skipped when there's no terminal, and creation completes. The prompt still runs when the preset is invoked directly via nx generate in a real terminal (the same spawn/inherited-TTY path the agent-chat CLI uses).
  • Test coverage: rename the no-interactive smoke test to create-workspace and add an interactive case that drives the preset generator through a PTY (node-pty, mirroring local-dev.spec.ts's chatStreamsReply) and answers the engagementId prompt — covering the previously untested interactive path. CI/PR matrix entry renamed accordingly.

Description of how you validated changes

  • Verified the module shape: with import * as enquirer, enquirer.prompt is undefined; with the default import it's a function.
  • Ran the create-workspace smoke test locally against the fixed build: the non-interactive npm/pnpm/yarn-4 cases pass, and the new interactive case drives the engagementId prompt end-to-end (types MyEngagementId, submits, asserts it's written as a tag in aws-nx-plugin.config.mts). (bun and yarn-classic fail only due to local env — bun not installed, and a local verdaccio transitive-dep passthrough quirk.)
  • pnpm nx run @aws/nx-plugin:build passes (lint + unit tests, 33 preset tests green).

Issue # (if applicable)

Closes #897.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

…ation works (#897)

`import * as enquirer` compiles to a native ESM namespace import since the
plugin migrated to ESM. enquirer is CommonJS with `prompt` assigned as a
runtime static, which the module lexer can't surface as a named export, so
`enquirer.prompt` was `undefined` and creating a workspace without
`--no-interactive` crashed with "enquirer.prompt is not a function". Switch to
a default import.

Also guard the engagementId prompt on `process.stdin.isTTY`:
`create-nx-workspace` runs the preset via `exec` (a data-less stdin pipe), so
the prompt would otherwise hang once the crash was fixed. The prompt still runs
when the preset is invoked directly via `nx generate` in a real terminal.

Rename the `no-interactive` smoke test to `create-workspace` and add an
interactive case that drives the preset generator through a PTY and answers the
engagementId prompt, covering the previously untested interactive path.
@codecov-commenter

codecov-commenter commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.36%. Comparing base (6edf130) to head (7a59ea8).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #898   +/-   ##
=======================================
  Coverage   87.36%   87.36%           
=======================================
  Files         155      155           
  Lines        5388     5388           
  Branches     1263     1263           
=======================================
  Hits         4707     4707           
  Misses        359      359           
  Partials      322      322           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

The enquirer default-import is the fix for the interactive workspace
creation crash; the process.stdin.isTTY guard is unnecessary.
@cogwirrel
cogwirrel merged commit 04c9bc7 into main Jul 7, 2026
52 checks passed
@cogwirrel
cogwirrel deleted the fix/preset-enquirer-interactive branch July 7, 2026 04:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(ts#preset): enquirer.prompt is not a function when creating a workspace interactively

3 participants