Skip to content

Disable interaction when running in lifecycle scripts#147

Closed
Fryuni wants to merge 1 commit into
masterfrom
non-interactive-script
Closed

Disable interaction when running in lifecycle scripts#147
Fryuni wants to merge 1 commit into
masterfrom
non-interactive-script

Conversation

@Fryuni

@Fryuni Fryuni commented Jul 16, 2026

Copy link
Copy Markdown
Member

Summary

Package-manager lifecycle hooks can currently block dependency installation by asking unrelated interactive questions, such as whether to enable deep links. This is especially problematic for pre* and post* scripts, which must run unattended.

This change detects npm-compatible lifecycle context through npm_lifecycle_event. Event names beginning with the case-sensitive pre or post prefixes force the CLI into its existing non-interactive path. The requested command still executes normally, but optional prompts and host-environment changes remain suppressed.

The solution:

  • injects a Process boundary into the CLI bootstrap and classifies lifecycle events with HasEnvVar;
  • applies lifecycle precedence to both Commander construction passes, so conditional options and arguments are mandatory before execution;
  • propagates the same process through recursive CLI invocations and Cli.fromDefaults;
  • reuses the injected process for current-directory resolution instead of constructing another signal-subscribing NodeProcess;
  • adds coverage for lifecycle, ordinary, missing, and explicit --no-interaction cases.

The existing SDK-generated croct --no-interaction install postinstall command remains unchanged as defense in depth.

Verification

  • npm test -- --runInBand --runTestsByPath test/infrastructure/application/cli/program.test.ts — 10 tests passed
  • npm run validate
  • npm run lint
  • npm run build
  • Lifecycle credential smoke test exited immediately with the mandatory --username diagnostic instead of prompting
  • Lifecycle logout smoke test exited successfully without update or deep-link questions

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • Documentation changes are not required for this internal bootstrap behavior
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing relevant unit tests pass locally with my changes
  • No downstream module changes are required
  • I have checked my code and corrected any misspellings

@github-actions

Copy link
Copy Markdown

👋 @Fryuni
Thanks for your contribution!
The approval and merge process is almost fully automated 🧙
Here's how it works:

  1. You open a new pull request
  2. Automated tests check the code
  3. Maintainers review the code
  4. Once approved, the PR is ready to merge.

👉 Omit the extended description
Please remove the commit body before merging the pull request.
Instead, include the pull request number in the title to provide the full context
about the change.

☝️ Lastly, the title for the commit will come from the pull request title. So please provide a descriptive title that summarizes the changes in 50 characters or less using the imperative mood.
Happy coding! 🎉

@pkg-pr-new

pkg-pr-new Bot commented Jul 16, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/croct@147

commit: 216b0ca

@Fryuni Fryuni changed the title fix: disable interaction in lifecycle scripts Disable interaction when running in lifecycle scripts Jul 16, 2026
@Fryuni Fryuni added the enhancement Improvement of existing features label Jul 16, 2026
@Fryuni Fryuni self-assigned this Jul 16, 2026
@marcospassos

Copy link
Copy Markdown
Member

Tks for the PR. As discussed, in newer versions, the CLI automatically include the no-interaction flag in the package script.

@marcospassos
marcospassos deleted the non-interactive-script branch July 16, 2026 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improvement of existing features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants