Commit 19ad85c
feat(init): install @ably/cli globally when launched via npx (#394)
* feat(init): install @ably/cli globally when launched via npx
`ably init` is the documented one-command onboarding entry point, but
`npx @ably/cli init` only landed the CLI in the ephemeral npx cache —
after init exited, `ably` was no longer on PATH. This change makes init
detect the npx invocation, prompt the user (default Y), and run
`npm install -g @ably/cli@latest` so the CLI persists across shells.
- Add `--no-install` flag for users who manage @ably/cli with their own
package manager.
- Install runs silently in --json mode (no prompt, stdio piped) so the
NDJSON stream stays clean for agent consumers.
- Install failures are non-fatal: a warning is logged with the captured
stderr and the user is told to run `npm install -g @ably/cli` manually.
- Extend `promptForConfirmation` with an optional `defaultYes` flag for
non-destructive prompts (empty answer counts as yes, suffix `[Y/n]`).
- Test hooks (`isRunningFromNpx`, `confirmGlobalInstall`,
`installGlobally`) follow the existing `runLogin` pattern so unit
tests never shell out to real `npm install -g`.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(init): address PR review feedback
- promptForConfirmation: add `[Y/n]` to the no-double-append guard so a
caller passing both a manual `[Y/n]` suffix and `{ defaultYes: true }`
doesn't get the suffix doubled. Adds regression test.
- init global-install warning: in non-JSON mode the underlying npm
process runs with `stdio: "inherit"` so npm has already printed the
real error to the user's terminal. The thrown error's `.message` is
just "Command failed: npm install -g @ably/cli@latest" — restating
that adds no information. Emit a terse warning in non-JSON mode and
keep the detailed warning (with captured stderr) in JSON mode where
npm output was piped. Update the failure-path test and add a new
JSON-mode failure test asserting captured stderr is surfaced.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(init): bound global install with timeout and emit JSON outcome event
Address PR review feedback:
- execSync had no timeout, so a flaky network or stalled npm registry could
leave `ably init` hung indefinitely with no feedback during onboarding.
Cap the global install at 120s; ETIMEDOUT flows through the existing
catch block as a non-fatal warning.
- In `--json` mode the install step was invisible to agents on success
(logProgress / logSuccessMessage are silent by design), so agents could
only detect install failure, never success or a skip. Emit one
structured `install` event per init run covering all outcomes:
installed, skipped (no-install-flag | not-npx), failed.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(init): check npx context before --no-install when skipping
Reorder the early-return guards in maybeInstallGlobally so the npx context
is checked first. --no-install is only meaningful when an install would
otherwise happen (i.e. when running via npx — the flag's own help text
says so). Previously `ably init --no-install --json` from a globally
installed binary would emit { status: "skipped", reason: "no-install-flag" }
even though the real reason it's skipped is that we're not in npx.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* Update src/commands/init.ts
Co-authored-by: sachin shinde <sachinshinde7676@gmail.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: sachin shinde <sachinshinde7676@gmail.com>1 parent 9233fd2 commit 19ad85c
4 files changed
Lines changed: 511 additions & 6 deletions
File tree
- src
- commands
- utils
- test/unit
- commands
- utils
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
1 | 4 | | |
2 | 5 | | |
3 | 6 | | |
| |||
10 | 13 | | |
11 | 14 | | |
12 | 15 | | |
| 16 | + | |
13 | 17 | | |
14 | 18 | | |
| 19 | + | |
15 | 20 | | |
16 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
17 | 28 | | |
18 | 29 | | |
19 | 30 | | |
| |||
23 | 34 | | |
24 | 35 | | |
25 | 36 | | |
| 37 | + | |
26 | 38 | | |
27 | 39 | | |
28 | 40 | | |
| |||
35 | 47 | | |
36 | 48 | | |
37 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
38 | 55 | | |
39 | 56 | | |
40 | 57 | | |
| |||
55 | 72 | | |
56 | 73 | | |
57 | 74 | | |
| 75 | + | |
| 76 | + | |
58 | 77 | | |
59 | 78 | | |
60 | 79 | | |
| |||
183 | 202 | | |
184 | 203 | | |
185 | 204 | | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
186 | 347 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | 5 | | |
7 | 6 | | |
8 | 7 | | |
9 | | - | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
10 | 11 | | |
11 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
12 | 16 | | |
13 | 17 | | |
14 | 18 | | |
15 | 19 | | |
16 | 20 | | |
17 | | - | |
| 21 | + | |
18 | 22 | | |
19 | 23 | | |
20 | 24 | | |
| 25 | + | |
21 | 26 | | |
22 | 27 | | |
23 | | - | |
| 28 | + | |
24 | 29 | | |
25 | 30 | | |
26 | 31 | | |
27 | 32 | | |
28 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
29 | 38 | | |
30 | 39 | | |
31 | 40 | | |
| |||
0 commit comments