@stagepass/cli 2.2.1 → 2.2.7

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.
package/README.md CHANGED
@@ -49,11 +49,11 @@ Linked: https://my-project.sp -> /absolute/path/to/project
49
49
  | Command | Description |
50
50
  | :--- | :--- |
51
51
  | `stagepass setup` | Install Caddy, PHP, Dnsmasq via Homebrew and configure the local `.sp` resolver (`address=/.sp/127.0.0.1` + `/etc/resolver/sp`). |
52
- | `stagepass start` | Start background Caddy & PHP services. Migrates legacy Caddyfile blocks if needed. |
52
+ | `stagepass start` | Start Caddy & PHP. No unconditional root warm-up: inspects port 443 without sudo; signals only after confirm (TERM then optional KILL). With autostart installed, bootstraps/kickstarts the LaunchAgent (else direct `caddy start`). |
53
53
  | `stagepass link [domain]` | Link the current directory to a `.sp` domain, write/update the Caddyfile + `~/.stagepass/projects.json`, reload Caddy. |
54
54
  | `stagepass unlink [domain]` | Remove the site block and `projects.json` entry, reload Caddy. |
55
55
  | `stagepass reload` | Reload Caddy configuration. Migrates legacy Caddyfile blocks if needed. |
56
- | `stagepass stop` | Stop background services. Prints a hint when login autostart is enabled. |
56
+ | `stagepass stop` | Stop Caddy & PHP. If autostart is installed/loaded, `launchctl bootout` first (until next login); use `autostart off` to disable permanently. |
57
57
  | `stagepass doctor` | Read-only diagnostics (Homebrew, Caddy, PHP/php-fpm, dnsmasq, resolver, port 443, Caddyfile, projects, certs, LaunchAgent, plus the current project's declared modules vs. its live site). Never uses sudo. `--json`, `--skip-site`. Exit `1` if any fail. |
58
58
  | `stagepass certs check` | Read-only Caddy local CA check (validity, System keychain trust, orphans, optional TLS handshake per linked domain). `--json`, `--skip-handshake`. |
59
59
  | `stagepass certs trust` | Run `caddy trust` after interactive confirmation (or `--yes`). |
@@ -70,10 +70,28 @@ All commands support `-v, --verbose` where applicable.
70
70
 
71
71
  - `doctor` and `certs check` are read-only. They never delete keychain items or certificate files.
72
72
  - Prefer CDN major pin `@2` in Webflow custom code (doctor warns if recommended snippets would use `@latest`).
73
- - Chrome may require Local Network Access permission for public HTTPS pages that load `https://*.sp` assets.
74
- - Autostart runs as your user (same privilege model as `caddy start` inside `stagepass start`). If port 443 cannot be bound, `daemon` logs a clear error and exits `0` so launchd KeepAlive does not restart-loop. Use interactive `stagepass start` to resolve conflicts.
73
+ - Autostart runs as your user (same privilege model as interactive `caddy start`). `start` kickstarts the agent when present; `stop` bootouts until the next login. If port 443 cannot be bound, `daemon` logs a clear error and exits `0` so launchd KeepAlive does not restart-loop. Interactive `start` confirms before signalling any non-caddy listener.
74
+ - `stagepass autostart on` records a launchd-safe `PATH` from `brew --prefix` (Apple Silicon `/opt/homebrew`, Intel `/usr/local`) plus `/usr/bin:/bin:/usr/sbin:/sbin`. It does **not** copy your interactive shell environment. `brew` and `caddy` must resolve to shims under that prefix's `bin`/`sbin` (normal Homebrew Cellar symlinks are fine). Missing Homebrew/Caddy aborts **before** writing the plist.
75
75
  - Manual macOS checklist: [`TESTING-macos.md`](./TESTING-macos.md).
76
76
 
77
+ #### macOS permissions (keep these separate)
78
+
79
+ These are different prompts. Grant only the narrow dialog macOS shows — Stagepass never asks for Full Disk Access or any security bypass.
80
+
81
+ | Concern | What it is | Typical fix |
82
+ | :--- | :--- | :--- |
83
+ | **System CA trust** | Trusting Caddy’s local CA in the System keychain (`stagepass certs trust` / `caddy trust`) so browsers accept `https://*.sp`. | Run `stagepass certs check`, then `certs trust` if needed. Unrelated to TCC file access. |
84
+ | **Browser Local Network Access** | Chrome (and similar) gating public HTTPS pages that fetch `https://*.sp` / loopback. | Allow Local Network for the **browser** when it prompts. Not a Node Desktop-files grant. |
85
+ | **Node files access (TCC)** | macOS may ask the **Node** binary for access to a folder (commonly **Desktop**) when the CLI or LaunchAgent reads a project / test package living there. | Grant that folder to Node if you intentionally keep projects on Desktop. Prefer installing the CLI in a stable location (below) so everyday use does not depend on Desktop TCC. |
86
+
87
+ #### Install location and LaunchAgent paths
88
+
89
+ - Prefer a **stable** global install (`npm install -g @stagepass/cli` into the normal npm prefix, or another fixed absolute path). Avoid pointing autostart at a temporary Desktop unpack / ad-hoc test tarball when you can use the published package instead.
90
+ - `autostart on` records **absolute** Node and CLI paths (often Homebrew Cellar Node + the realpathed `stagepass` entry) plus the validated Homebrew `PATH`. It does not follow later `brew` upgrades automatically.
91
+ - After a Homebrew Node upgrade/cleanup, moving the CLI, or changing the npm prefix, run `stagepass autostart on` again so ProgramArguments stay valid. A brief local outage while the agent reloads is expected.
92
+ - Upgrading the global CLI package does **not** rewrite an existing LaunchAgent that still points at an older test path. Switch deliberately: `stagepass autostart off` then `autostart on` with the stable CLI you want. Do **not** delete a test directory while a loaded agent still references it — disable/refresh the agent first.
93
+ - Development checkouts (`packages/cli`, Desktop test packs) and the published global install are different binaries; compare behaviour with one style at a time.
94
+
77
95
  ### `new` options
78
96
 
79
97
  Scaffold a project with flags for every choice (interactive prompts only on a TTY without `--yes`):
@@ -239,6 +257,17 @@ stagepass link --no-allow-all-origins
239
257
 
240
258
  Hand-written content outside `# START:` / `# END:` markers is left untouched. Unparsable legacy blocks are left unchanged with a warning. Migration is idempotent (second run does nothing and creates no new backup).
241
259
 
260
+ ## Troubleshooting (CLI)
261
+
262
+ | Symptom | What to check |
263
+ | :--- | :--- |
264
+ | Autostart runs at login but `caddy: command not found` / daemon exits | Re-run `stagepass autostart on` on **2.2.7+** so the plist embeds Homebrew `PATH`. Confirm `brew --prefix` and that `which caddy` points at `$prefix/bin/caddy` (Cellar symlink OK). |
265
+ | macOS asks Node for Desktop access | Normal TCC when the CLI/agent reads a project under Desktop. Grant the folder or move the project / use a stable global CLI install. Not the same as browser Local Network or CA trust. |
266
+ | Autostart still runs an old Desktop test binary after `npm i -g` | Global upgrade does not migrate LaunchAgent ProgramArguments. `autostart off` then `on` with the stable CLI; do not remove the old path while the agent still references it. |
267
+ | `stagepass start` spinner floods the terminal (weird ANSI) | Upgrade to 2.2.7+ (spinner geometry guard). Rare with TTY width `0`. |
268
+ | `start` asks for a password at every boot | 2.2.7+ drops unconditional `sudo -v`. Only confirmed conflict resolution may use `sudo kill` / `apachectl`. |
269
+ | Port 443 bind failure under LaunchAgent | Expected when something else owns 443; daemon exits `0` (no restart loop). Free the port or use interactive `stagepass start`. |
270
+
242
271
  ## Related Packages
243
272
 
244
273
  - `@stagepass/loader`: browser runtime for swapping production assets.
package/TESTING-macos.md CHANGED
@@ -40,17 +40,26 @@ stagepass start
40
40
  - [ ] After trust, Safari / Chrome / Firefox show a valid certificate for `https://my-project.sp`
41
41
  - [ ] There is **no** `certs renew` command in 2.1.0
42
42
 
43
+ ## Permissions (do not conflate)
44
+
45
+ - [ ] **CA trust** checked via `certs check` / `certs trust` (System keychain) — separate from TCC
46
+ - [ ] **Browser Local Network Access** granted in the browser if the live site loads `*.sp` — separate from Node
47
+ - [ ] If macOS prompts **Node** for **Desktop** (or another folder) access because the project/test pack lives there, grant that folder only — not Full Disk Access
48
+ - [ ] Prefer a stable `npm install -g @stagepass/cli` path for acceptance; temporary Desktop test packs are fine for a one-off check but refresh autostart before deleting them
49
+
43
50
  ## autostart / daemon
44
51
 
45
52
  - [ ] `stagepass autostart status` shows label `io.github.arobertherz.stagepass`
46
- - [ ] `stagepass autostart on` writes `~/Library/LaunchAgents/io.github.arobertherz.stagepass.plist` with absolute node + CLI paths
53
+ - [ ] `stagepass autostart on` writes `~/Library/LaunchAgents/io.github.arobertherz.stagepass.plist` with absolute node + CLI paths and an `EnvironmentVariables` `PATH` that includes Homebrew `bin`/`sbin` from `brew --prefix` (Cellar symlink for `caddy` is OK)
54
+ - [ ] With a sparse launchd-like PATH, `daemon` still finds `caddy` via the plist PATH
47
55
  - [ ] Plist has `RunAtLoad` and `KeepAlive` / `SuccessfulExit` false
48
56
  - [ ] Logs appear under `~/.stagepass/logs/`
49
- - [ ] After logout/login (or `launchctl bootstrap`), daemon starts Caddy via `caddy run`
50
- - [ ] `stagepass stop` still stops services; when autostart is on it prints a hint that login may restart Caddy
57
+ - [ ] `stagepass start` does **not** prompt for sudo when port 443 is free / only caddy listens; with a foreign listener it asks before SIGTERM and again before SIGKILL
58
+ - [ ] With autostart on: bootstrap if needed, kickstart via `start`; `stop` bootouts (until next login) then stops Caddy/PHP; `autostart off` / `on` retained
59
+ - [ ] After moving Node/CLI or leaving a Desktop test path, `autostart off` then `on` with the stable CLI (upgrade alone does not migrate ProgramArguments)
51
60
  - [ ] `stagepass autostart off` boots out the agent and removes the plist
52
61
  - [ ] If port 443 cannot be bound, daemon logs a clear message and exits `0` (no KeepAlive restart-loop; not a silent success)
53
- - [ ] Cold-start daemon logs cert root/trust only (no TLS handshake attempts before `caddy run`)
62
+ - [ ] Optional separate checklist: logout/login cold boot of **this** installed version (not assumed by the 2.2.7 interactive accept)
54
63
 
55
64
  ## Regression (must stay unchanged)
56
65
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stagepass/cli",
3
- "version": "2.2.1",
3
+ "version": "2.2.7",
4
4
  "description": "Local Development Orchestrator for Webflow",
5
5
  "type": "module",
6
6
  "main": "bin/index.js",
@@ -2,7 +2,7 @@ import fs from 'fs-extra';
2
2
  import path from 'path';
3
3
  import chalk from 'chalk';
4
4
  import { execa } from 'execa';
5
- import ora from 'ora';
5
+ import { createSpinner } from '../lib/spinner.js';
6
6
  import { resolveLinkDomain } from '../lib/domain.js';
7
7
  import { renderSiteBlock, upsertBlock, parseBlocks } from '../lib/caddyfile.js';
8
8
  import {
@@ -87,7 +87,7 @@ export async function link(domain, options = {}) {
87
87
  );
88
88
  }
89
89
 
90
- const spinner = ora(`Linking ${chalk.bold(targetDomain)}...`).start();
90
+ const spinner = createSpinner(`Linking ${chalk.bold(targetDomain)}...`).start();
91
91
 
92
92
  try {
93
93
  await fs.ensureDir(caddyDir);
@@ -25,6 +25,7 @@ import {
25
25
  fetchPublished,
26
26
  installedHasPerModuleTypes,
27
27
  rangeHasPerModuleTypes,
28
+ resolveSnippetLoaderVersion,
28
29
  } from '../lib/registry.js';
29
30
  import { updateConfigTypes } from '../lib/project-sync.js';
30
31
 
@@ -33,14 +34,10 @@ const PER_MODULE_TYPES_HINT =
33
34
  'types use "@stagepass/modules" for now. Run `stagepass upgrade` once it is published to narrow them.';
34
35
 
35
36
  /**
36
- * Resolve a boolean flag that may appear as --foo / --no-foo.
37
- * Only argv is trusted: Commander defaults negated pairs to true, which would
38
- * break defaults like --install (off unless passed).
39
- *
40
37
  * @param {object} _options
41
38
  * @param {string} key
42
39
  * @param {string[]} argv
43
- * @param {boolean|undefined} defaultValue undefined = still unset
40
+ * @param {boolean|undefined} defaultValue
44
41
  */
45
42
  export function resolveBoolFlag(_options, key, argv, defaultValue) {
46
43
  const pos = `--${key}`;
@@ -51,7 +48,7 @@ export function resolveBoolFlag(_options, key, argv, defaultValue) {
51
48
  }
52
49
 
53
50
  /**
54
- * @param {object} options Commander options
51
+ * @param {object} options
55
52
  * @param {object} [deps]
56
53
  */
57
54
  async function resolveAuthor(options, deps) {
@@ -95,7 +92,6 @@ async function askYesNo(rl, question, defaultYes) {
95
92
  }
96
93
 
97
94
  /**
98
- * Merge flags + optional interactive prompts into a resolved config.
99
95
  * @param {string|undefined} nameArg
100
96
  * @param {object} options
101
97
  * @param {object} deps
@@ -115,7 +111,7 @@ export async function resolveNewOptions(nameArg, options = {}, deps = {}) {
115
111
  let styles =
116
112
  options.styles === 'css' || options.styles === 'scss' ? options.styles : '';
117
113
 
118
- // Prefer argv for --foo / --no-foo so Commander default quirks do not flip defaults.
114
+ // Prefer argv for --foo / --no-foo so Commander defaults do not flip.
119
115
  let modules = resolveBoolFlag(options, 'modules', argv, undefined);
120
116
  let git = resolveBoolFlag(options, 'git', argv, undefined);
121
117
  let install = resolveBoolFlag(options, 'install', argv, undefined);
@@ -139,9 +135,9 @@ export async function resolveNewOptions(nameArg, options = {}, deps = {}) {
139
135
  }
140
136
 
141
137
  /**
142
- * Detect modules on the live site (public GET, never executed).
143
- * @returns {Promise<string[] | null>} detected list, or null when unknown
144
- */
138
+ * Detect modules on the live site (public GET, never executed).
139
+ * @returns {Promise<string[] | null>} detected list, or null when unknown
140
+ */
145
141
  const detectFromSite = async () => {
146
142
  if (!origin) return null;
147
143
  log(`Checking live site https://${origin}/ for Stagepass script tags...`);
@@ -231,7 +227,7 @@ export async function resolveNewOptions(nameArg, options = {}, deps = {}) {
231
227
  error: '--no-modules conflicts with declared site modules. Drop --no-modules or pass --site-modules none.',
232
228
  };
233
229
  }
234
- // The npm package (types) follows the declared list; keep the legacy default (included).
230
+ // npm package (types) follows the declared list; legacy default is included.
235
231
  if (siteModules.length > 0) modules = true;
236
232
 
237
233
  // Non-interactive / --yes defaults
@@ -289,16 +285,13 @@ export async function resolveNewOptions(nameArg, options = {}, deps = {}) {
289
285
  remote: remoteCheck.remote,
290
286
  install,
291
287
  dryRun: options.dryRun === true,
292
- loaderVersion:
293
- deps.packagesVersion || deps.cliVersion || STAGEPASS_PACKAGES_VERSION,
288
+ // Bundled loader until createNew resolves the published one (AC-14).
289
+ loaderVersion: deps.packagesVersion || STAGEPASS_PACKAGES_VERSION,
294
290
  },
295
291
  };
296
292
  }
297
293
 
298
294
  /**
299
- * After `npm install`, align tsconfig/jsconfig types with the installed
300
- * @stagepass/modules (per-module entries only when it ships them).
301
- *
302
295
  * @param {string} targetDir
303
296
  * @param {{ siteModules: string[], perModuleTypes?: boolean }} config
304
297
  * @param {typeof fs} fse
@@ -324,8 +317,6 @@ async function reconcileInstalledTypes(targetDir, config, fse, log) {
324
317
  }
325
318
 
326
319
  /**
327
- * Scaffold a new Stagepass project.
328
- *
329
320
  * @param {string|undefined} nameArg
330
321
  * @param {object} [options]
331
322
  * @param {object} [deps]
@@ -375,9 +366,7 @@ export async function createNew(nameArg, options = {}, deps = {}) {
375
366
  }
376
367
  };
377
368
 
378
- // Single-module types (`@stagepass/modules/cookies`) exist since modules
379
- // 2.2.0. Only use them when a published release in range ships them;
380
- // otherwise (or offline) fall back to the umbrella types so tsc passes.
369
+ // Per-module types since modules 2.2.0; else umbrella types so tsc passes.
381
370
  const singleModuleTypes =
382
371
  config.modules === true &&
383
372
  config.siteModules.length > 0 &&
@@ -389,6 +378,17 @@ export async function createNew(nameArg, options = {}, deps = {}) {
389
378
  if (!config.perModuleTypes) log(chalk.yellow(PER_MODULE_TYPES_HINT));
390
379
  }
391
380
 
381
+ // Snippets pin the resolved loader, never the CLI version (AC-14).
382
+ if (!config.dryRun) {
383
+ const loader = await (deps.fetchPublished || fetchPublished)('@stagepass/loader', { exec });
384
+ config.loaderVersion = await resolveSnippetLoaderVersion({
385
+ published: loader,
386
+ cwd: targetDir,
387
+ bundled: config.loaderVersion,
388
+ fse,
389
+ });
390
+ }
391
+
392
392
  let files;
393
393
  try {
394
394
  files = await planScaffoldFiles(config, { readTemplate });
@@ -507,5 +507,5 @@ export async function createNew(nameArg, options = {}, deps = {}) {
507
507
  return 0;
508
508
  }
509
509
 
510
- /** Commander-facing alias */
510
+ /** Commander-facing alias */
511
511
  export const newProject = createNew;
@@ -1,6 +1,6 @@
1
1
  import chalk from 'chalk';
2
2
  import { execa } from 'execa';
3
- import ora from 'ora';
3
+ import { createSpinner } from '../lib/spinner.js';
4
4
  import fs from 'fs-extra';
5
5
  import { getCaddyfilePath, getProjectsPath } from '../lib/paths.js';
6
6
  import {
@@ -12,7 +12,7 @@ export async function reload(options = {}) {
12
12
  const caddyFilePath = getCaddyfilePath();
13
13
  const projectsPath = getProjectsPath();
14
14
 
15
- const spinner = ora('Reloading Caddy...').start();
15
+ const spinner = createSpinner('Reloading Caddy...').start();
16
16
 
17
17
  if (!(await fs.pathExists(caddyFilePath))) {
18
18
  spinner.fail('No Caddyfile found. Run "stagepass link" first.');
@@ -1,5 +1,5 @@
1
1
  import { execa } from 'execa';
2
- import ora from 'ora';
2
+ import { createSpinner } from '../lib/spinner.js';
3
3
  import chalk from 'chalk';
4
4
  import fs from 'fs-extra';
5
5
  import path from 'path';
@@ -21,7 +21,7 @@ export async function setup(options = {}) {
21
21
  const execOpts = options.verbose ? { stdio: 'inherit' } : {};
22
22
 
23
23
  // 1. Check Homebrew
24
- const brewSpinner = ora('Checking system requirements...').start();
24
+ const brewSpinner = createSpinner('Checking system requirements...').start();
25
25
  try {
26
26
  await execa('brew', ['--version']);
27
27
  brewSpinner.succeed('System requirements met.');
@@ -31,7 +31,7 @@ export async function setup(options = {}) {
31
31
  }
32
32
 
33
33
  // 2. Install Dependencies
34
- const installSpinner = ora('Installing dependencies...').start();
34
+ const installSpinner = createSpinner('Installing dependencies...').start();
35
35
  try {
36
36
  await execa('brew', ['install', 'caddy', 'php', 'dnsmasq'], execOpts);
37
37
  installSpinner.succeed('Core dependencies installed.');
@@ -41,7 +41,7 @@ export async function setup(options = {}) {
41
41
  }
42
42
 
43
43
  // 3. Configure Dnsmasq (DIRECT WRITE STRATEGY)
44
- const dnsSpinner = ora('Configuring local DNS (.sp)...').start();
44
+ const dnsSpinner = createSpinner('Configuring local DNS (.sp)...').start();
45
45
  try {
46
46
  const { stdout: brewPrefixRaw } = await execa('brew', ['--prefix']);
47
47
  const brewPrefix = brewPrefixRaw.trim();
@@ -82,7 +82,7 @@ export async function setup(options = {}) {
82
82
  }
83
83
 
84
84
  // 5. Restart DNS Services
85
- const restartSpinner = ora('Restarting DNS services...').start();
85
+ const restartSpinner = createSpinner('Restarting DNS services...').start();
86
86
  try {
87
87
  // Dnsmasq Restart
88
88
  try {