@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.
@@ -13,12 +13,13 @@ import { STAGEPASS_PACKAGES_VERSION } from '../lib/versions.js';
13
13
  import {
14
14
  PACKAGES_MAJOR_RANGE,
15
15
  fetchPublished,
16
+ resolveSnippetLoaderVersion,
16
17
  installedHasPerModuleTypes,
17
18
  maxSatisfying,
18
19
  rangeHasPerModuleTypes,
19
20
  satisfiesSimple,
20
21
  } from '../lib/registry.js';
21
- import { detectSite } from '../lib/site-detect.js';
22
+ import { detectSite, normalizeSiteUrl } from '../lib/site-detect.js';
22
23
  import {
23
24
  applyProjectSync,
24
25
  planProjectSync,
@@ -31,7 +32,6 @@ const STAGEPASS_SCOPE = '@stagepass/';
31
32
  const SAFE_SPEC_RE = /^[~^]?[0-9A-Za-z][0-9A-Za-z._+-]*$/;
32
33
 
33
34
  /**
34
- * True when the version looks like an npm dist-tag (bare word, e.g. latest).
35
35
  * @param {string} version
36
36
  */
37
37
  function isDistTag(version) {
@@ -43,15 +43,7 @@ function isDistTag(version) {
43
43
  }
44
44
 
45
45
  /**
46
- * Resolve the range to write for one @stagepass/* package.
47
- *
48
- * Never writes a version or range that no published release satisfies
49
- * (releases can be staged but not yet approved, which gives ETARGET):
50
- * - default: `^<latest>` when latest is in the current major, else
51
- * `^<highest published 2.x>`; `^2` when npm is unreachable
52
- * - `--version <semver|range>`: must match a published version
53
- * - `--version <dist-tag>`: the published version behind that tag
54
- *
46
+ * Never writes a version/range no published release satisfies (avoids ETARGET on staged releases).
55
47
  * @param {string} name
56
48
  * @param {string|undefined} requested
57
49
  * @param {{ distTags: Record<string, string>, versions: string[] } | null} published
@@ -96,8 +88,6 @@ export function resolvePackageTarget(name, requested, published) {
96
88
  }
97
89
 
98
90
  /**
99
- * Resolve target ranges for every @stagepass/* dependency in package.json.
100
- *
101
91
  * @param {string|undefined} requested `--version`
102
92
  * @param {string[]} names package names
103
93
  * @param {object} [deps]
@@ -120,7 +110,6 @@ export async function resolveUpgradeTargets(requested, names, deps = {}) {
120
110
  }
121
111
 
122
112
  /**
123
- * Collect @stagepass/* entries from dependencies and devDependencies.
124
113
  * @param {object} pkg
125
114
  * @returns {{ section: 'dependencies'|'devDependencies', name: string, from: string }[]}
126
115
  */
@@ -140,7 +129,6 @@ export function findStagepassDeps(pkg) {
140
129
  }
141
130
 
142
131
  /**
143
- * Rewrite @stagepass/* versions in a package.json object (mutates a copy).
144
132
  * @param {object} pkg
145
133
  * @param {string | Record<string, string>} target one spec for all, or per package name
146
134
  * @returns {{ next: object, changes: { name: string, from: string, to: string, section: string }[] }}
@@ -163,10 +151,6 @@ export function applyStagepassVersions(pkg, target) {
163
151
  }
164
152
 
165
153
  /**
166
- * Upgrade @stagepass/* deps in the current project's package.json and sync
167
- * the declared modules into stagepass.json, AGENTS.md, the Cursor rule and
168
- * tsconfig/jsconfig types.
169
- *
170
154
  * @param {object} [options]
171
155
  * @param {boolean} [options.dryRun]
172
156
  * @param {string} [options.version]
@@ -202,6 +186,14 @@ export async function upgrade(options = {}, deps = {}) {
202
186
  return 1;
203
187
  }
204
188
 
189
+ if (options.site) {
190
+ const c = normalizeSiteUrl(options.site);
191
+ if (!c.ok) {
192
+ log(chalk.red(c.error));
193
+ return 1;
194
+ }
195
+ }
196
+
205
197
  const names = findStagepassDeps(pkg).map((d) => d.name);
206
198
  let resolvedTargets;
207
199
  try {
@@ -319,6 +311,27 @@ export async function upgrade(options = {}, deps = {}) {
319
311
  );
320
312
  }
321
313
 
314
+ // Snippet: --version pin of loader on 2.x wins; resolve before writing so a failure changes nothing.
315
+ let loaderPub = '@stagepass/loader' in published ? published['@stagepass/loader'] : undefined;
316
+ const getLoaderPub = async () => {
317
+ if (loaderPub !== undefined) return loaderPub;
318
+ const lookup = deps.fetchPublished || ((name) => fetchPublished(name, { exec: deps.exec || defaultExec }));
319
+ loaderPub = await lookup('@stagepass/loader');
320
+ return loaderPub;
321
+ };
322
+ let snippetVersion = null;
323
+ if (options.version != null) {
324
+ let t = targets['@stagepass/loader'];
325
+ if (!t) {
326
+ try {
327
+ t = resolvePackageTarget('@stagepass/loader', options.version, await getLoaderPub());
328
+ } catch (e) {
329
+ log(chalk.red(e instanceof Error ? e.message : String(e)));
330
+ return 1;
331
+ }
332
+ }
333
+ if (t.resolved && satisfiesSimple(t.resolved, PACKAGES_MAJOR_RANGE)) snippetVersion = t.resolved;
334
+ }
322
335
  if (options.dryRun) {
323
336
  log(chalk.dim('\nDry run: no files were modified.'));
324
337
  } else {
@@ -332,8 +345,16 @@ export async function upgrade(options = {}, deps = {}) {
332
345
  if (plan.writes.length > 0) log(chalk.green(`Updated ${plan.writes.length} project file(s).`));
333
346
  }
334
347
 
348
+ if (!snippetVersion) {
349
+ snippetVersion = await resolveSnippetLoaderVersion({
350
+ published: await getLoaderPub(),
351
+ cwd,
352
+ bundled: STAGEPASS_PACKAGES_VERSION,
353
+ fse,
354
+ });
355
+ }
335
356
  const snippets = buildWebflowSnippets({
336
- version: targets['@stagepass/loader']?.resolved || STAGEPASS_PACKAGES_VERSION,
357
+ version: snippetVersion,
337
358
  moduleList: resolved.modules,
338
359
  });
339
360
  printWebflowSnippets(snippets, log);
@@ -12,6 +12,9 @@ import {
12
12
  } from './paths.js';
13
13
  import { defaultExec, resolveCommand } from './exec.js';
14
14
 
15
+ /** Default PATH used by macOS user LaunchAgents (no Homebrew). */
16
+ export const LAUNCHD_MINIMAL_PATH = '/usr/bin:/bin:/usr/sbin:/sbin';
17
+
15
18
  /**
16
19
  * Escape a string for use inside an XML plist text node.
17
20
  * @param {string} value
@@ -25,6 +28,33 @@ export function escapeXml(value) {
25
28
  .replace(/'/g, '&apos;');
26
29
  }
27
30
 
31
+ /**
32
+ * Build LaunchAgent PATH: validated Homebrew bin/sbin + launchd minimal dirs.
33
+ * Does not inherit the interactive user environment.
34
+ * @param {string} brewPrefix Absolute Homebrew prefix (`brew --prefix`)
35
+ * @returns {string}
36
+ */
37
+ export function buildAutostartPathEnv(brewPrefix) {
38
+ if (typeof brewPrefix !== 'string' || brewPrefix.length === 0) {
39
+ throw new Error('brewPrefix is required');
40
+ }
41
+ if (!path.isAbsolute(brewPrefix)) {
42
+ throw new Error(`brewPrefix must be absolute (got: ${brewPrefix})`);
43
+ }
44
+ if (/[\r\n\0]/.test(brewPrefix)) {
45
+ throw new Error('brewPrefix must not contain control characters');
46
+ }
47
+ // `:` would split PATH entries; reject before embedding.
48
+ if (brewPrefix.includes(path.delimiter)) {
49
+ throw new Error(
50
+ `brewPrefix must not contain PATH delimiter (${path.delimiter})`
51
+ );
52
+ }
53
+ const bin = path.join(brewPrefix, 'bin');
54
+ const sbin = path.join(brewPrefix, 'sbin');
55
+ return `${bin}${path.delimiter}${sbin}${path.delimiter}${LAUNCHD_MINIMAL_PATH}`;
56
+ }
57
+
28
58
  /**
29
59
  * Build LaunchAgent ProgramArguments for `stagepass daemon`.
30
60
  * @param {{ nodePath: string, cliPath: string }} paths
@@ -64,6 +94,17 @@ export function buildLaunchctlPrintArgs(uid, label = LAUNCH_AGENT_LABEL) {
64
94
  return ['print', `gui/${uid}/${label}`];
65
95
  }
66
96
 
97
+ /**
98
+ * launchctl kickstart arguments (gui domain).
99
+ * `-k` kills any existing instance before starting.
100
+ * @param {number|string} uid
101
+ * @param {string} [label]
102
+ * @returns {string[]}
103
+ */
104
+ export function buildLaunchctlKickstartArgs(uid, label = LAUNCH_AGENT_LABEL) {
105
+ return ['kickstart', '-k', `gui/${uid}/${label}`];
106
+ }
107
+
67
108
  /**
68
109
  * Render a LaunchAgent plist that runs `stagepass daemon` at login.
69
110
  *
@@ -72,9 +113,13 @@ export function buildLaunchctlPrintArgs(uid, label = LAUNCH_AGENT_LABEL) {
72
113
  * same bind privileges as interactive `start` on macOS. If bind fails at
73
114
  * runtime, `daemon` logs a clear error and exits 0 so KeepAlive does not loop.
74
115
  *
116
+ * `pathEnv` is required so launchd (minimal PATH) can still resolve Homebrew
117
+ * `brew` / `caddy` by bare name without inheriting the interactive user env.
118
+ *
75
119
  * @param {object} opts
76
120
  * @param {string} opts.nodePath
77
121
  * @param {string} opts.cliPath
122
+ * @param {string} opts.pathEnv Validated PATH for EnvironmentVariables
78
123
  * @param {string} [opts.label]
79
124
  * @param {string} [opts.stdoutPath]
80
125
  * @param {string} [opts.stderrPath]
@@ -89,6 +134,13 @@ export function renderLaunchAgentPlist(opts) {
89
134
  const stdoutPath = opts.stdoutPath || getDaemonStdoutLogPath();
90
135
  const stderrPath = opts.stderrPath || getDaemonStderrLogPath();
91
136
  const workingDirectory = opts.workingDirectory || os.homedir();
137
+ const pathEnv = opts.pathEnv;
138
+ if (typeof pathEnv !== 'string' || pathEnv.length === 0) {
139
+ throw new Error('pathEnv is required for LaunchAgent EnvironmentVariables');
140
+ }
141
+ if (/[\r\n\0]/.test(pathEnv)) {
142
+ throw new Error('pathEnv must not contain control characters');
143
+ }
92
144
 
93
145
  const argXml = programArguments
94
146
  .map((a) => `\t\t<string>${escapeXml(a)}</string>`)
@@ -106,6 +158,11 @@ ${argXml}
106
158
  \t</array>
107
159
  \t<key>WorkingDirectory</key>
108
160
  \t<string>${escapeXml(workingDirectory)}</string>
161
+ \t<key>EnvironmentVariables</key>
162
+ \t<dict>
163
+ \t\t<key>PATH</key>
164
+ \t\t<string>${escapeXml(pathEnv)}</string>
165
+ \t</dict>
109
166
  \t<key>RunAtLoad</key>
110
167
  \t<true/>
111
168
  \t<key>KeepAlive</key>
@@ -220,6 +277,228 @@ export async function resolveAutostartPaths(opts = {}) {
220
277
  return { ok: true, nodePath, cliPath: cliCheck.path, error: null };
221
278
  }
222
279
 
280
+ /**
281
+ * True when `absolutePath` is the Homebrew prefix or a path beneath it.
282
+ * @param {string} absolutePath
283
+ * @param {string} brewPrefix
284
+ */
285
+ function isPathUnderPrefix(absolutePath, brewPrefix) {
286
+ return (
287
+ absolutePath === brewPrefix ||
288
+ absolutePath.startsWith(`${brewPrefix}${path.sep}`)
289
+ );
290
+ }
291
+
292
+ /**
293
+ * Validate a tool as launchd will see it: the PATH shim must live in
294
+ * `prefix/bin` or `prefix/sbin`. The realpath target may be under Cellar
295
+ * (normal Homebrew layout) but must remain under the same prefix, be a
296
+ * regular file, and be executable.
297
+ *
298
+ * @param {object} opts
299
+ * @param {string} opts.name
300
+ * @param {string} opts.shimPath Absolute path returned by `which` / PATH lookup
301
+ * @param {string} opts.brewPrefix
302
+ * @param {(p: string) => Promise<string>} opts.realpath
303
+ * @param {(p: string) => Promise<boolean>} opts.pathExists
304
+ * @param {(p: string) => Promise<import('node:fs').Stats>} opts.stat
305
+ * @returns {Promise<{ ok: true, path: string, canonicalPath: string } | { ok: false, error: string }>}
306
+ */
307
+ async function validatePrefixPathTool(opts) {
308
+ const { name, shimPath, brewPrefix, realpath, pathExists, stat } = opts;
309
+ const shimCheck = await requireAbsoluteExistingPath(shimPath, name, pathExists);
310
+ if (!shimCheck.ok) return shimCheck;
311
+
312
+ const prefixBin = path.join(brewPrefix, 'bin');
313
+ const prefixSbin = path.join(brewPrefix, 'sbin');
314
+ const shimDir = path.dirname(shimCheck.path);
315
+ if (shimDir !== prefixBin && shimDir !== prefixSbin) {
316
+ return {
317
+ ok: false,
318
+ error: `${name} PATH entry must be in ${prefixBin} or ${prefixSbin} (got ${shimDir}).`,
319
+ };
320
+ }
321
+
322
+ let canonicalPath;
323
+ try {
324
+ canonicalPath = await realpath(shimCheck.path);
325
+ } catch (error) {
326
+ return {
327
+ ok: false,
328
+ error: `Could not realpath ${name} at ${shimCheck.path}: ${
329
+ error instanceof Error ? error.message : String(error)
330
+ }`,
331
+ };
332
+ }
333
+
334
+ if (!isPathUnderPrefix(canonicalPath, brewPrefix)) {
335
+ return {
336
+ ok: false,
337
+ error: `${name} realpath (${canonicalPath}) is not under brew --prefix (${brewPrefix}).`,
338
+ };
339
+ }
340
+
341
+ let st;
342
+ try {
343
+ st = await stat(canonicalPath);
344
+ } catch (error) {
345
+ return {
346
+ ok: false,
347
+ error: `Could not stat ${name} at ${canonicalPath}: ${
348
+ error instanceof Error ? error.message : String(error)
349
+ }`,
350
+ };
351
+ }
352
+ if (!st.isFile()) {
353
+ return {
354
+ ok: false,
355
+ error: `${name} resolves to a non-file: ${canonicalPath}`,
356
+ };
357
+ }
358
+ if (!(st.mode & 0o111)) {
359
+ return {
360
+ ok: false,
361
+ error: `${name} is not executable: ${canonicalPath}`,
362
+ };
363
+ }
364
+
365
+ return { ok: true, path: shimCheck.path, canonicalPath };
366
+ }
367
+
368
+ /**
369
+ * Resolve Homebrew + Caddy for the LaunchAgent runtime environment.
370
+ * Uses the interactive enable-time PATH to locate tools, then records a
371
+ * launchd-safe PATH from the validated `brew --prefix` (Apple Silicon
372
+ * `/opt/homebrew` or Intel `/usr/local` via brew itself — not hardcoded).
373
+ *
374
+ * PATH shims must sit in `prefix/bin` or `prefix/sbin`. Realpaths may point
375
+ * into `Cellar/...` (standard Homebrew) as long as they stay under the prefix.
376
+ *
377
+ * @param {object} [opts]
378
+ * @param {import('./exec.js').ExecFn} [opts.exec]
379
+ * @param {(p: string) => Promise<string>} [opts.realpath]
380
+ * @param {(p: string) => Promise<boolean>} [opts.pathExists]
381
+ * @param {(p: string) => Promise<import('node:fs').Stats>} [opts.stat]
382
+ * @returns {Promise<{
383
+ * ok: boolean,
384
+ * error?: string,
385
+ * brewPath?: string,
386
+ * caddyPath?: string,
387
+ * brewPrefix?: string,
388
+ * pathEnv?: string,
389
+ * }>}
390
+ */
391
+ export async function resolveAutostartRuntimeEnvironment(opts = {}) {
392
+ const exec = opts.exec || defaultExec;
393
+ const realpath =
394
+ opts.realpath || ((p) => fs.realpath(p).then((r) => String(r)));
395
+ const pathExists = opts.pathExists || ((p) => fs.pathExists(p));
396
+ const stat = opts.stat || ((p) => fs.stat(p));
397
+
398
+ const brewWhich = await resolveCommand('brew', exec);
399
+ if (!brewWhich) {
400
+ return {
401
+ ok: false,
402
+ error:
403
+ 'Homebrew `brew` not found. Install Homebrew and ensure it is on PATH before enabling autostart.',
404
+ };
405
+ }
406
+ const brewShim = path.resolve(brewWhich);
407
+ const brewShimCheck = await requireAbsoluteExistingPath(
408
+ brewShim,
409
+ 'brew',
410
+ pathExists
411
+ );
412
+ if (!brewShimCheck.ok) {
413
+ return { ok: false, error: brewShimCheck.error };
414
+ }
415
+
416
+ let brewPrefix = '';
417
+ try {
418
+ // Invoke via the PATH shim (not Cellar realpath) — matches user `brew --prefix`.
419
+ const { stdout } = await exec(brewShimCheck.path, ['--prefix']);
420
+ brewPrefix = String(stdout || '').trim();
421
+ } catch (error) {
422
+ return {
423
+ ok: false,
424
+ error: `Could not read Homebrew prefix via brew --prefix: ${
425
+ error instanceof Error ? error.message : String(error)
426
+ }`,
427
+ };
428
+ }
429
+
430
+ if (!brewPrefix || !path.isAbsolute(brewPrefix) || /[\r\n\0]/.test(brewPrefix)) {
431
+ return {
432
+ ok: false,
433
+ error: `Invalid Homebrew prefix from brew --prefix: ${brewPrefix || '(empty)'}`,
434
+ };
435
+ }
436
+ if (brewPrefix.includes(path.delimiter)) {
437
+ return {
438
+ ok: false,
439
+ error: `Homebrew prefix contains PATH delimiter: ${brewPrefix}`,
440
+ };
441
+ }
442
+
443
+ const prefixBin = path.join(brewPrefix, 'bin');
444
+ if (!(await pathExists(prefixBin))) {
445
+ return {
446
+ ok: false,
447
+ error: `Homebrew prefix bin directory does not exist: ${prefixBin}`,
448
+ };
449
+ }
450
+
451
+ const brewTool = await validatePrefixPathTool({
452
+ name: 'brew',
453
+ shimPath: brewShimCheck.path,
454
+ brewPrefix,
455
+ realpath,
456
+ pathExists,
457
+ stat,
458
+ });
459
+ if (!brewTool.ok) {
460
+ return { ok: false, error: brewTool.error };
461
+ }
462
+
463
+ const caddyWhich = await resolveCommand('caddy', exec);
464
+ if (!caddyWhich) {
465
+ return {
466
+ ok: false,
467
+ error:
468
+ 'Caddy not found. Run `stagepass setup` (or `brew install caddy`) before enabling autostart.',
469
+ };
470
+ }
471
+ const caddyTool = await validatePrefixPathTool({
472
+ name: 'caddy',
473
+ shimPath: path.resolve(caddyWhich),
474
+ brewPrefix,
475
+ realpath,
476
+ pathExists,
477
+ stat,
478
+ });
479
+ if (!caddyTool.ok) {
480
+ return { ok: false, error: caddyTool.error };
481
+ }
482
+
483
+ let pathEnv;
484
+ try {
485
+ pathEnv = buildAutostartPathEnv(brewPrefix);
486
+ } catch (error) {
487
+ return {
488
+ ok: false,
489
+ error: error instanceof Error ? error.message : String(error),
490
+ };
491
+ }
492
+
493
+ return {
494
+ ok: true,
495
+ brewPath: brewTool.path,
496
+ caddyPath: caddyTool.path,
497
+ brewPrefix,
498
+ pathEnv,
499
+ };
500
+ }
501
+
223
502
  /**
224
503
  * @param {object} [opts]
225
504
  * @param {import('./exec.js').ExecFn} [opts.exec]
@@ -264,6 +543,7 @@ export async function getAutostartStatus(opts = {}) {
264
543
  export async function enableAutostart(opts = {}) {
265
544
  const exec = opts.exec || defaultExec;
266
545
  const uid = opts.uid ?? process.getuid?.() ?? os.userInfo().uid;
546
+ const pathExists = opts.pathExists || ((p) => fs.pathExists(p));
267
547
  const paths =
268
548
  opts.paths ||
269
549
  (await resolveAutostartPaths({
@@ -271,7 +551,7 @@ export async function enableAutostart(opts = {}) {
271
551
  argv1: opts.argv1,
272
552
  exec,
273
553
  realpath: opts.realpath,
274
- pathExists: opts.pathExists,
554
+ pathExists,
275
555
  }));
276
556
 
277
557
  if (!paths.ok) {
@@ -285,7 +565,6 @@ export async function enableAutostart(opts = {}) {
285
565
  error: 'Autostart nodePath and cliPath must be absolute.',
286
566
  };
287
567
  }
288
- const pathExists = opts.pathExists || ((p) => fs.pathExists(p));
289
568
  if (!(await pathExists(paths.nodePath)) || !(await pathExists(paths.cliPath))) {
290
569
  return {
291
570
  ok: false,
@@ -293,18 +572,36 @@ export async function enableAutostart(opts = {}) {
293
572
  };
294
573
  }
295
574
 
575
+ const runtime =
576
+ opts.runtime ||
577
+ (await resolveAutostartRuntimeEnvironment({
578
+ exec,
579
+ realpath: opts.realpath,
580
+ pathExists,
581
+ }));
582
+ if (!runtime.ok || !runtime.pathEnv) {
583
+ return {
584
+ ok: false,
585
+ error:
586
+ runtime.error ||
587
+ 'Could not resolve Homebrew/Caddy paths for LaunchAgent PATH.',
588
+ };
589
+ }
590
+
296
591
  const plistPath = opts.plistPath || getLaunchAgentPlistPath();
297
592
  const agentsDir = path.dirname(plistPath);
298
593
  const ensureDir = opts.ensureDir || ((p) => fs.ensureDir(p));
299
594
  const writeFile = opts.writeFile || ((p, c) => fs.writeFile(p, c, 'utf8'));
300
595
  const logsDir = opts.logsDir || getLogsDir();
301
596
 
597
+ // Write only after node/cli + Homebrew/Caddy prerequisites validate.
302
598
  await ensureDir(agentsDir);
303
599
  await ensureDir(logsDir);
304
600
 
305
601
  const plist = renderLaunchAgentPlist({
306
602
  nodePath: paths.nodePath,
307
603
  cliPath: paths.cliPath,
604
+ pathEnv: runtime.pathEnv,
308
605
  stdoutPath: opts.stdoutPath || getDaemonStdoutLogPath(),
309
606
  stderrPath: opts.stderrPath || getDaemonStderrLogPath(),
310
607
  workingDirectory: opts.workingDirectory || os.homedir(),
@@ -330,7 +627,7 @@ export async function enableAutostart(opts = {}) {
330
627
  };
331
628
  }
332
629
 
333
- return { ok: true, plistPath, paths, error: null };
630
+ return { ok: true, plistPath, paths, runtime, error: null };
334
631
  }
335
632
 
336
633
  /**
@@ -1,7 +1,6 @@
1
1
  /**
2
- * Doctor checks for the current project folder: declared modules in
3
- * stagepass.json vs. the Stagepass scripts the live Webflow site loads.
4
- * Read-only: one public GET of the live page, parsed and never executed.
2
+ * Doctor checks: declared modules vs Stagepass scripts on the live site.
3
+ * Read-only public GET; HTML parsed, never executed.
5
4
  */
6
5
 
7
6
  import path from 'node:path';
@@ -41,7 +40,7 @@ export async function runProjectSiteChecks(opts = {}) {
41
40
  }
42
41
 
43
42
  if (opts.skipSite) return checks;
44
- const found = await resolveProjectOrigin(cwd, sp.data, { loadProjects: opts.loadProjects });
43
+ const found = await resolveProjectOrigin(cwd, sp.data, { loadProjects: opts.loadProjects, log: opts.log });
45
44
  if (!found) {
46
45
  checks.push({
47
46
  id: 'project.site',
@@ -1,12 +1,5 @@
1
1
  /**
2
- * Sync generated project files with the declared Stagepass modules
3
- * (used by `stagepass upgrade` and `stagepass doctor`).
4
- *
5
- * Writes only:
6
- * - stagepass.json `modules` (and `origin` when passed via --site)
7
- * - AGENTS.md managed block (created when missing)
8
- * - .cursor/rules/stagepass.mdc (created when missing, managed block refreshed)
9
- * - tsconfig.json / jsconfig.json `compilerOptions.types` (plain JSON only)
2
+ * Sync generated project files with declared Stagepass modules
10
3
  */
11
4
 
12
5
  import path from 'node:path';
@@ -25,10 +18,9 @@ import {
25
18
  typesForModules,
26
19
  } from './project-modules.js';
27
20
  import { loadProjects } from './projects.js';
28
- import { describeDetection, normalizeSiteUrl } from './site-detect.js';
21
+ import { describeDetection, normalizeSiteUrl, SITE_PORT_ERROR } from './site-detect.js';
29
22
 
30
23
  /**
31
- * Read and parse stagepass.json (null when missing or invalid).
32
24
  * @param {string} cwd
33
25
  * @param {typeof fs} [fse]
34
26
  * @returns {Promise<{ exists: boolean, data: Record<string, unknown> | null, raw: string, error?: string }>}
@@ -49,7 +41,6 @@ export async function readStagepassJson(cwd, fse = fs) {
49
41
  }
50
42
 
51
43
  /**
52
- * Declared modules from stagepass.json (`null` when missing or legacy boolean).
53
44
  * @param {Record<string, unknown> | null} data
54
45
  * @returns {string[] | null}
55
46
  */
@@ -59,10 +50,11 @@ export function declaredModules(data) {
59
50
  return result.ok ? result.modules : null;
60
51
  }
61
52
 
53
+ function warnPortSkip(log, source) {
54
+ if (log) log(`Skipped ${source}: it contains a port. Use the host only, e.g. my-site.webflow.io.`);
55
+ }
56
+
62
57
  /**
63
- * Live origin for a project: stagepass.json `origin`, else the first concrete
64
- * (non-wildcard) origin stored by `stagepass link` for this project folder.
65
- *
66
58
  * @param {string} cwd
67
59
  * @param {Record<string, unknown> | null} data
68
60
  * @param {{ loadProjects?: typeof loadProjects, realpath?: (p: string) => Promise<string> }} [deps]
@@ -72,6 +64,7 @@ export async function resolveProjectOrigin(cwd, data, deps = {}) {
72
64
  if (data && typeof data.origin === 'string' && data.origin.trim() !== '') {
73
65
  const check = normalizeSiteUrl(data.origin);
74
66
  if (check.ok) return { origin: check.host, source: 'stagepass.json' };
67
+ if (check.error === SITE_PORT_ERROR) warnPortSkip(deps.log, 'stagepass.json origin');
75
68
  }
76
69
  const load = deps.loadProjects || loadProjects;
77
70
  const realpath = deps.realpath || ((p) => fs.realpath(p));
@@ -99,21 +92,18 @@ export async function resolveProjectOrigin(cwd, data, deps = {}) {
99
92
  for (const origin of Array.isArray(entry.origins) ? entry.origins : []) {
100
93
  const check = normalizeSiteUrl(String(origin));
101
94
  if (check.ok) return { origin: check.host, source: 'stagepass link' };
95
+ if (check.error === SITE_PORT_ERROR) warnPortSkip(deps.log, 'linked origin from stagepass link');
102
96
  }
103
97
  }
104
98
  return null;
105
99
  }
106
100
 
107
101
  /**
108
- * Decide the declared modules list for `upgrade`.
109
- * Order: --site-modules flag, live site detection, existing stagepass.json,
110
- * interactive prompt. The npm dependency is only mentioned as a hint.
111
- *
112
102
  * @param {object} input
113
103
  * @param {string} input.cwd
114
- * @param {Record<string, unknown> | null} input.data stagepass.json
115
- * @param {object} input.pkg package.json
116
- * @param {object} input.options { siteModules?, site?, skipSite?, yes? }
104
+ * @param {Record<string, unknown> | null} input.data
105
+ * @param {object} input.pkg
106
+ * @param {object} input.options
117
107
  * @param {object} deps
118
108
  * @param {(site: string) => Promise<any>} deps.detectSite
119
109
  * @param {(question: string, def: string) => Promise<string>} [deps.ask]
@@ -147,7 +137,7 @@ export async function resolveUpgradeModules(input, deps) {
147
137
  if (!check.ok) return { ok: false, error: check.error };
148
138
  origin = check.host;
149
139
  } else {
150
- const found = await resolveProjectOrigin(cwd, data, { loadProjects: deps.loadProjects });
140
+ const found = await resolveProjectOrigin(cwd, data, { loadProjects: deps.loadProjects, log });
151
141
  origin = found ? found.origin : null;
152
142
  }
153
143
 
@@ -179,9 +169,7 @@ export async function resolveUpgradeModules(input, deps) {
179
169
  source = 'stagepass.json';
180
170
  }
181
171
 
182
- // Legacy `"modules": true` (CLI 2.0/2.1) meant "modules included", typed via
183
- // `@stagepass/modules` (all modules). Keep that as `["all"]` so an upgrade
184
- // without a live site result never removes types the project relied on.
172
+ // Legacy `"modules": true` meant all modules typed; keep as `["all"]` without a live site.
185
173
  if (!candidate && data?.modules === true) {
186
174
  candidate = ['all'];
187
175
  source = 'legacy "modules": true in stagepass.json';
@@ -228,9 +216,7 @@ export async function resolveUpgradeModules(input, deps) {
228
216
  }
229
217
 
230
218
  /**
231
- * Update `compilerOptions.types` in a tsconfig/jsconfig source.
232
- *
233
- * @param {string} raw file contents
219
+ * @param {string} raw
234
220
  * @param {string[]} modules
235
221
  * @param {{ modulesDependency: boolean, perModuleTypes?: boolean }} opts
236
222
  * @returns {{ status: 'updated' | 'unchanged' | 'skipped', content?: string, reason?: string, types?: string[] }}
@@ -273,14 +259,12 @@ export function updateConfigTypes(raw, modules, opts) {
273
259
  }
274
260
 
275
261
  /**
276
- * Plan file changes for the declared modules (pure, no writes).
277
- *
278
262
  * @param {object} input
279
263
  * @param {string} input.cwd
280
264
  * @param {string[]} input.modules
281
- * @param {string | null} [input.origin] stored in stagepass.json when set
282
- * @param {object} input.pkg package.json
283
- * @param {boolean} [input.perModuleTypes] false when @stagepass/modules has no per-module types (umbrella entry)
265
+ * @param {string | null} [input.origin]
266
+ * @param {object} input.pkg
267
+ * @param {boolean} [input.perModuleTypes]
284
268
  * @param {typeof fs} [fse]
285
269
  * @returns {Promise<{ writes: { file: string, content: string, action: string }[], notes: string[] }>}
286
270
  */
@@ -388,7 +372,6 @@ export async function planProjectSync(input, fse = fs) {
388
372
  }
389
373
 
390
374
  /**
391
- * Write planned changes (skips when dryRun).
392
375
  * @param {string} cwd
393
376
  * @param {{ file: string, content: string }[]} writes
394
377
  * @param {typeof fs} [fse]