@ninhache/probe 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +11 -2
  2. package/dist/cli.js +17 -3
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # probe
2
2
 
3
+ [![npm](https://img.shields.io/npm/v/@ninhache/probe)](https://www.npmjs.com/package/@ninhache/probe)
4
+ [![Homebrew](https://img.shields.io/badge/homebrew-ninhache%2Ftap-orange)](https://github.com/Ninhache/homebrew-tap)
5
+ [![CI](https://github.com/Ninhache/probe/actions/workflows/ci.yml/badge.svg)](https://github.com/Ninhache/probe/actions/workflows/ci.yml)
6
+ [![License: MIT](https://img.shields.io/npm/l/@ninhache/probe)](LICENSE)
7
+
3
8
  Declare your project's local services once. Check they are up with one command, or with `make check`.
4
9
 
5
10
  ```console
@@ -63,6 +68,9 @@ services:
63
68
  | `path` | `/` | Path requested with `GET` |
64
69
  | `expect` | any 2xx | Expected status, or a list of statuses |
65
70
 
71
+ Redirects are followed and the final status is judged, unless `expect` contains a 3xx: then the first response
72
+ is judged as is.
73
+
66
74
  Files in `.probe/`:
67
75
 
68
76
  - `config.yml`: services. Commit it.
@@ -85,7 +93,8 @@ never touched.
85
93
  Targets: `help`, `check`, `status` and one `check-<name>` per service. The block uses `probe` when it is in
86
94
  your `PATH`, else `npx -y @ninhache/probe@latest`. It works with GNU Make 3.81 (the macOS default).
87
95
 
88
- Edited the block by hand? `probe status` says so, `probe sync` restores it.
96
+ Edited the block by hand? `probe status` says so and `probe add` / `probe rm` leave it alone. `probe sync`
97
+ restores it.
89
98
 
90
99
  ## Migrations
91
100
 
@@ -125,7 +134,7 @@ make check PROBE="node ../../dist/cli.js"
125
134
  Release: bump `version` in `package.json`, merge, then push a `v<version>` tag. The Release workflow publishes
126
135
  to npm through trusted publishing: no token, the package trusts this repo's `release.yml` (set on npmjs.com,
127
136
  package Settings, Trusted Publisher). It then opens a PR on `ninhache/homebrew-tap` with the new `url` and
128
- `sha256` (secret `HOMEBREW_TAP_TOKEN`): merge it once the tap's CI is green.
137
+ `sha256` (secret `HOMEBREW_TAP_TOKEN`), which merges itself once the tap's CI is green.
129
138
 
130
139
  ## License
131
140
 
package/dist/cli.js CHANGED
@@ -292,7 +292,7 @@ async function writeLock(paths, lock) {
292
292
  }
293
293
 
294
294
  // src/version.ts
295
- var CLI_VERSION = true ? "0.1.1" : "0.0.0-dev";
295
+ var CLI_VERSION = true ? "0.1.2" : "0.0.0-dev";
296
296
 
297
297
  // src/makefile/generator.ts
298
298
  import { createHash } from "crypto";
@@ -408,8 +408,15 @@ function rawServices(loaded) {
408
408
  return loaded.raw.services ?? {};
409
409
  }
410
410
  async function saveServices(loaded, services) {
411
+ const edited = await blockState(loaded.paths, loaded.config) === "modified";
411
412
  const saved = await saveConfig(loaded, { ...loaded.raw, services });
412
- await syncMakefile(saved.paths, saved.config);
413
+ if (!edited) {
414
+ await syncMakefile(saved.paths, saved.config);
415
+ return;
416
+ }
417
+ console.error(
418
+ "probe: the Makefile block was edited by hand, left as is. Run `probe sync` to regenerate it."
419
+ );
413
420
  }
414
421
 
415
422
  // src/commands/add.ts
@@ -470,6 +477,9 @@ function isExpected(expect, status) {
470
477
  if (expect === void 0) return status >= 200 && status < 300;
471
478
  return Array.isArray(expect) ? expect.includes(status) : expect === status;
472
479
  }
480
+ function expectsRedirect(expect) {
481
+ return [expect ?? []].flat().some((status) => status >= 300 && status < 400);
482
+ }
473
483
  function describeExpected(expect) {
474
484
  if (expect === void 0) return "2xx";
475
485
  return Array.isArray(expect) ? expect.join(" or ") : String(expect);
@@ -491,7 +501,11 @@ var httpChecker = {
491
501
  const started = performance.now();
492
502
  const elapsed = () => Math.round(performance.now() - started);
493
503
  try {
494
- const response = await fetch(target, { signal: AbortSignal.timeout(timeoutMs) });
504
+ const response = await fetch(target, {
505
+ signal: AbortSignal.timeout(timeoutMs),
506
+ // Following a redirect hides its status: an expected 3xx could never match.
507
+ redirect: expectsRedirect(service.expect) ? "manual" : "follow"
508
+ });
495
509
  const latencyMs = elapsed();
496
510
  await response.body?.cancel();
497
511
  const { status } = response;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ninhache/probe",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Health checks for your local dev services, from the CLI or a generated Makefile",
5
5
  "license": "MIT",
6
6
  "author": "Ninhache",