@stagepass/cli 2.2.7 → 2.3.0

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 (46) hide show
  1. package/README.md +37 -18
  2. package/TESTING-macos.md +28 -10
  3. package/bin/index.js +4 -1
  4. package/package.json +9 -8
  5. package/src/cli.js +62 -7
  6. package/src/commands/certs.js +375 -19
  7. package/src/commands/daemon.js +75 -7
  8. package/src/commands/dev.js +419 -0
  9. package/src/commands/link.js +64 -23
  10. package/src/commands/new.js +397 -41
  11. package/src/commands/npm-run.js +8 -0
  12. package/src/commands/start.js +220 -127
  13. package/src/commands/stop.js +10 -19
  14. package/src/commands/unlink.js +6 -4
  15. package/src/commands/upgrade.js +51 -12
  16. package/src/lib/apply-site-block.js +48 -0
  17. package/src/lib/caddyfile.js +72 -13
  18. package/src/lib/cdn-snippets.js +145 -3
  19. package/src/lib/certs.js +334 -47
  20. package/src/lib/dev-port.js +45 -0
  21. package/src/lib/doctor-site.js +61 -5
  22. package/src/lib/doctor.js +48 -4
  23. package/src/lib/ensure-running.js +89 -0
  24. package/src/lib/exec.js +72 -24
  25. package/src/lib/live-server.js +484 -0
  26. package/src/lib/node-engine.js +55 -0
  27. package/src/lib/notify.js +62 -0
  28. package/src/lib/origins.js +27 -5
  29. package/src/lib/package-versions.js +9 -0
  30. package/src/lib/paths.js +18 -0
  31. package/src/lib/php-fpm.js +33 -0
  32. package/src/lib/project-sync.js +165 -20
  33. package/src/lib/projects.js +137 -7
  34. package/src/lib/prompts.js +47 -0
  35. package/src/lib/registry.js +27 -6
  36. package/src/lib/scaffold.js +288 -11
  37. package/src/lib/site-detect.js +78 -25
  38. package/src/lib/snippets.js +14 -11
  39. package/src/lib/versions.js +20 -8
  40. package/templates/project/AGENTS.md.tmpl +4 -3
  41. package/templates/project/README.md.tmpl +35 -6
  42. package/templates/project/api/README.md.tmpl +7 -0
  43. package/templates/project/examples/php/README.md.tmpl +18 -0
  44. package/templates/project/examples/php/form.php +105 -0
  45. package/templates/project/examples/php/proxy.php +171 -0
  46. package/templates/project/scripts/build.mjs +200 -37
package/src/lib/certs.js CHANGED
@@ -2,8 +2,13 @@ import fs from 'fs-extra';
2
2
  import path from 'node:path';
3
3
  import { X509Certificate } from 'node:crypto';
4
4
  import tls from 'node:tls';
5
- import { getCaddyRootCaPath } from './paths.js';
5
+ import {
6
+ getCaddyRootCaPath,
7
+ getCaddyCertificatesLocalDir,
8
+ getCaddyPkiAuthoritiesLocalDir,
9
+ } from './paths.js';
6
10
  import { defaultExec } from './exec.js';
11
+ import { validateDomain } from './domain.js';
7
12
 
8
13
  /** Warn when the root CA expires within this many days. */
9
14
  export const ROOT_EXPIRY_WARN_DAYS = 90;
@@ -142,16 +147,7 @@ export function parseSecurityFindCertificateOutput(output) {
142
147
  return results;
143
148
  }
144
149
 
145
- /**
146
- * Compare local root against System keychain trust store (report only).
147
- * Never deletes keychain items.
148
- *
149
- * @param {object} opts
150
- * @param {string} opts.rootFingerprintSha256
151
- * @param {import('./exec.js').ExecFn} [opts.exec]
152
- * @param {string} [opts.keychainPath]
153
- * @param {string} [opts.searchName]
154
- */
150
+ /** Compare local root fingerprint to System keychain (report only). */
155
151
  export async function inspectKeychainTrust(opts) {
156
152
  const exec = opts.exec || defaultExec;
157
153
  const keychainPath =
@@ -191,14 +187,7 @@ export async function inspectKeychainTrust(opts) {
191
187
  };
192
188
  }
193
189
 
194
- /**
195
- * Read and assess the on-disk Caddy local root CA.
196
- * @param {object} [opts]
197
- * @param {string} [opts.rootPath]
198
- * @param {Date} [opts.now]
199
- * @param {(p: string) => Promise<boolean>} [opts.pathExists]
200
- * @param {(p: string, enc: string) => Promise<string>} [opts.readFile]
201
- */
190
+ /** Assess on-disk Caddy local root CA. */
202
191
  export async function checkLocalRootCa(opts = {}) {
203
192
  const rootPath = opts.rootPath || getCaddyRootCaPath();
204
193
  const pathExists = opts.pathExists || ((p) => fs.pathExists(p));
@@ -254,16 +243,31 @@ export async function checkLocalRootCa(opts = {}) {
254
243
  };
255
244
  }
256
245
 
246
+ /** True when lsof shows caddy on TCP 443. */
247
+ export async function isCaddyServing443(opts = {}) {
248
+ const exec = opts.exec || defaultExec;
249
+ try {
250
+ const { stdout } = await exec('lsof', ['-nP', '-iTCP:443', '-sTCP:LISTEN']);
251
+ return String(stdout || '').split('\n').some((line) => {
252
+ const cmd = line.trim().split(/\s+/)[0] || '';
253
+ return cmd && cmd !== 'COMMAND' && /caddy/i.test(cmd);
254
+ });
255
+ } catch {
256
+ return false;
257
+ }
258
+ }
259
+
260
+ /** @param {object} opts */
261
+ async function resolveCaddyServing443(opts) {
262
+ return typeof opts.caddyServing443 === 'boolean'
263
+ ? opts.caddyServing443
264
+ : isCaddyServing443({ exec: opts.exec });
265
+ }
266
+
257
267
  /**
258
- * Optional TLS handshake against 127.0.0.1:443 with SNI.
259
- * rejectUnauthorized is false; validity dates and SAN are checked manually.
260
- *
268
+ * TLS handshake to 127.0.0.1:443 with SNI (rejectUnauthorized false).
261
269
  * @param {object} opts
262
270
  * @param {string} opts.servername
263
- * @param {string} [opts.host]
264
- * @param {number} [opts.port]
265
- * @param {number} [opts.timeoutMs]
266
- * @param {Date} [opts.now]
267
271
  * @param {typeof tls.connect} [opts.connect]
268
272
  */
269
273
  export function handshakeLocalDomain(opts) {
@@ -312,7 +316,7 @@ export function handshakeLocalDomain(opts) {
312
316
  });
313
317
  return;
314
318
  }
315
- const validity = assessCertificateValidity(peer, { now });
319
+ const validity = assessCertificateValidity(peer, { now, warnDays: 0 });
316
320
  if (validity.status === 'fail') {
317
321
  finish({
318
322
  status: 'fail',
@@ -376,10 +380,7 @@ export function handshakeLocalDomain(opts) {
376
380
  });
377
381
  }
378
382
 
379
- /**
380
- * Full read-only certificate report for doctor / certs check.
381
- * @param {object} [opts]
382
- */
383
+ /** Read-only cert report for doctor / certs check / start. */
383
384
  export async function runCertsCheck(opts = {}) {
384
385
  const root = await checkLocalRootCa({
385
386
  rootPath: opts.rootPath,
@@ -416,6 +417,7 @@ export async function runCertsCheck(opts = {}) {
416
417
  }
417
418
 
418
419
  // Report-only: Homebrew service data dir may hold a second CA.
420
+ // Exclude its fingerprint from orphans so --remove-orphans never deletes a still-valid brew root.
419
421
  if (opts.brewPrefix) {
420
422
  const secondary = path.join(
421
423
  opts.brewPrefix,
@@ -428,49 +430,334 @@ export async function runCertsCheck(opts = {}) {
428
430
  'root.crt'
429
431
  );
430
432
  const pathExists = opts.pathExists || ((p) => fs.pathExists(p));
433
+ const readFile = opts.readFile || ((p, enc) => fs.readFile(p, enc));
431
434
  if (await pathExists(secondary)) {
435
+ let fingerprint256 = null;
436
+ try {
437
+ const pem = await readFile(secondary, 'utf8');
438
+ const cert = loadCertificate(pem);
439
+ fingerprint256 = normalizeFingerprint(cert.fingerprint256);
440
+ } catch {
441
+ // Still report the path; exclusion only when the fingerprint is readable.
442
+ }
432
443
  report.secondaryRoots.push({
433
444
  path: secondary,
445
+ fingerprint256,
434
446
  note: 'Additional Caddy root found (Homebrew service data dir). Report only; not deleted.',
435
447
  });
448
+ if (fingerprint256) {
449
+ const filterOrphans = (list) =>
450
+ (list || []).filter((o) => o.sha256 !== fingerprint256);
451
+ report.orphans = filterOrphans(report.orphans);
452
+ if (report.trust) {
453
+ report.trust.orphans = filterOrphans(report.trust.orphans);
454
+ }
455
+ }
436
456
  }
437
457
  }
438
458
 
439
459
  const domains = Array.isArray(opts.domains) ? opts.domains : [];
440
460
  if (opts.skipHandshake !== true && domains.length > 0) {
441
- for (const domain of domains) {
442
- const result = await handshakeLocalDomain({
443
- servername: domain,
444
- host: opts.handshakeHost,
445
- port: opts.handshakePort,
446
- timeoutMs: opts.handshakeTimeoutMs,
447
- now: opts.now,
448
- connect: opts.connect,
449
- });
450
- report.handshakes.push(result);
461
+ if (!(await resolveCaddyServing443(opts))) {
462
+ for (const domain of domains) {
463
+ report.handshakes.push({
464
+ status: 'skip',
465
+ servername: domain,
466
+ reason: 'Caddy is not serving :443; TLS not checkable.',
467
+ });
468
+ }
469
+ } else {
470
+ for (const domain of domains) {
471
+ report.handshakes.push(
472
+ await handshakeLocalDomain({
473
+ servername: domain,
474
+ host: opts.handshakeHost,
475
+ port: opts.handshakePort,
476
+ timeoutMs: opts.handshakeTimeoutMs,
477
+ now: opts.now,
478
+ connect: opts.connect,
479
+ })
480
+ );
481
+ }
451
482
  }
452
483
  }
453
484
 
454
485
  return report;
455
486
  }
456
487
 
457
- /**
458
- * Guard: this module never deletes files or keychain items.
459
- * Exported for unit tests.
460
- */
488
+ /** Gated renew ops only; permanent root/CN deletes stay off. */
461
489
  export const DESTRUCTIVE_CERT_OPS = Object.freeze({
462
490
  deleteRoot: false,
491
+ deleteKeychainItemByCn: false,
492
+ /** @deprecated same as deleteKeychainItemByCn */
463
493
  deleteKeychainItem: false,
494
+ /** @deprecated use renewRootMoveBackup */
464
495
  renewRoot: false,
496
+ renewRootMoveBackup: true,
497
+ renewSiteCertDir: true,
498
+ deleteKeychainItemBySha1: true,
465
499
  });
466
500
 
467
- export function assertNoDestructiveCertOps() {
501
+ /** @returns {true} */
502
+ export function assertReadOnlyCertOps() {
468
503
  if (
469
504
  DESTRUCTIVE_CERT_OPS.deleteRoot ||
505
+ DESTRUCTIVE_CERT_OPS.deleteKeychainItemByCn ||
470
506
  DESTRUCTIVE_CERT_OPS.deleteKeychainItem ||
471
507
  DESTRUCTIVE_CERT_OPS.renewRoot
472
508
  ) {
473
- throw new Error('Destructive certificate operations must stay disabled.');
509
+ throw new Error(
510
+ 'Permanent root delete and CN-wildcard keychain delete must stay disabled.'
511
+ );
474
512
  }
475
513
  return true;
476
514
  }
515
+
516
+ /** @deprecated use assertReadOnlyCertOps */
517
+ export function assertNoDestructiveCertOps() {
518
+ return assertReadOnlyCertOps();
519
+ }
520
+
521
+ /**
522
+ * @param {'renewRootMoveBackup'|'renewSiteCertDir'|'deleteKeychainItemBySha1'} op
523
+ */
524
+ export function assertDestructiveCertOpAllowed(op) {
525
+ if (!DESTRUCTIVE_CERT_OPS[op]) {
526
+ throw new Error(`Destructive certificate operation is disabled: ${op}`);
527
+ }
528
+ return true;
529
+ }
530
+
531
+ /** SHA-1 fingerprint: 40 hex chars, uppercase, no separators. */
532
+ export function normalizeSha1Fingerprint(value) {
533
+ const sha1 = normalizeFingerprint(value);
534
+ if (!/^[0-9A-F]{40}$/.test(sha1)) {
535
+ return {
536
+ ok: false,
537
+ error: 'SHA-1 fingerprint must be exactly 40 hex characters.',
538
+ };
539
+ }
540
+ return { ok: true, sha1 };
541
+ }
542
+
543
+ /** Argv for `security delete-certificate -Z` (never by CN). */
544
+ export function buildSecurityDeleteCertificateArgs(
545
+ sha1,
546
+ keychainPath = '/Library/Keychains/System.keychain'
547
+ ) {
548
+ const normalized = normalizeSha1Fingerprint(sha1);
549
+ if (!normalized.ok) return normalized;
550
+ if (typeof keychainPath !== 'string' || !keychainPath.trim()) {
551
+ return { ok: false, error: 'Keychain path is required.' };
552
+ }
553
+ return {
554
+ ok: true,
555
+ args: ['delete-certificate', '-Z', normalized.sha1, keychainPath],
556
+ };
557
+ }
558
+
559
+ /** Linked `.sp` site cert dir under certificates/local (no traversal/symlinks). */
560
+ export async function resolveSafeSiteCertDir(opts) {
561
+ assertDestructiveCertOpAllowed('renewSiteCertDir');
562
+
563
+ const validated = validateDomain(opts.domain);
564
+ if (!validated.ok) {
565
+ return { ok: false, error: validated.error };
566
+ }
567
+ const domain = validated.domain;
568
+ const linked = new Set(
569
+ [...(opts.linkedDomains || [])].map((d) => String(d).toLowerCase())
570
+ );
571
+ if (!linked.has(domain)) {
572
+ return {
573
+ ok: false,
574
+ error: `Domain ${domain} is not a linked Stagepass project.`,
575
+ };
576
+ }
577
+
578
+ const base = path.resolve(
579
+ opts.certificatesLocalDir || getCaddyCertificatesLocalDir()
580
+ );
581
+ const candidate = path.resolve(base, domain);
582
+
583
+ if (!candidate.startsWith(`${base}${path.sep}`)) {
584
+ return { ok: false, error: 'Resolved certificate path escapes the local store.' };
585
+ }
586
+ if (candidate.includes('..')) {
587
+ return { ok: false, error: 'Certificate path must not contain .. segments.' };
588
+ }
589
+
590
+ const pathExists = opts.pathExists || ((p) => fs.pathExists(p));
591
+ if (!(await pathExists(candidate))) {
592
+ return { ok: false, error: `Certificate directory does not exist: ${candidate}` };
593
+ }
594
+
595
+ const lstat = opts.lstat || ((p) => fs.lstat(p));
596
+ let stats;
597
+ try {
598
+ stats = await lstat(candidate);
599
+ } catch (error) {
600
+ return {
601
+ ok: false,
602
+ error: `Could not lstat certificate directory: ${
603
+ error instanceof Error ? error.message : String(error)
604
+ }`,
605
+ };
606
+ }
607
+
608
+ if (stats.isSymbolicLink()) {
609
+ return { ok: false, error: 'Refusing to touch a symlinked certificate path.' };
610
+ }
611
+ if (!stats.isDirectory()) {
612
+ return { ok: false, error: 'Certificate path is not a directory.' };
613
+ }
614
+
615
+ return { ok: true, dir: candidate };
616
+ }
617
+
618
+ /**
619
+ * Delete failing site cert dirs then reload Caddy (or defer if Caddy is down).
620
+ * @param {object} opts
621
+ */
622
+ export async function renewSiteCertificates(opts) {
623
+ assertDestructiveCertOpAllowed('renewSiteCertDir');
624
+ const exec = opts.exec || defaultExec;
625
+ const remove = opts.remove || ((p) => fs.remove(p));
626
+ const domains = Array.isArray(opts.domains) ? opts.domains : [];
627
+ /** @type {{ domain: string, dir: string }[]} */
628
+ const deleted = [];
629
+ /** @type {{ domain: string, error: string }[]} */
630
+ const errors = [];
631
+
632
+ for (const domain of domains) {
633
+ const resolved = await resolveSafeSiteCertDir({
634
+ domain,
635
+ linkedDomains: opts.linkedDomains,
636
+ certificatesLocalDir: opts.certificatesLocalDir,
637
+ lstat: opts.lstat,
638
+ pathExists: opts.pathExists,
639
+ });
640
+ if (!resolved.ok) {
641
+ errors.push({ domain: String(domain), error: resolved.error });
642
+ continue;
643
+ }
644
+ const normalized = validateDomain(domain);
645
+ const domainLabel = normalized.ok ? normalized.domain : String(domain);
646
+ try {
647
+ await remove(resolved.dir);
648
+ deleted.push({ domain: domainLabel, dir: resolved.dir });
649
+ } catch (error) {
650
+ errors.push({
651
+ domain: domainLabel,
652
+ error: error instanceof Error ? error.message : String(error),
653
+ });
654
+ }
655
+ }
656
+
657
+ let reloaded = false;
658
+ let reloadError = null;
659
+ let reloadDeferred = false;
660
+ if (deleted.length > 0) {
661
+ if (!(await resolveCaddyServing443({ ...opts, exec }))) {
662
+ reloadDeferred = true;
663
+ } else {
664
+ try {
665
+ const reloadArgs = ['reload'];
666
+ if (opts.caddyfilePath) {
667
+ reloadArgs.push('--config', opts.caddyfilePath);
668
+ }
669
+ await exec('caddy', reloadArgs);
670
+ reloaded = true;
671
+ } catch (error) {
672
+ reloadError = error instanceof Error ? error.message : String(error);
673
+ }
674
+ }
675
+ }
676
+
677
+ return { deleted, errors, reloaded, reloadError, reloadDeferred };
678
+ }
679
+
680
+ /** Move local CA authority folder to a timestamped backup (never delete). */
681
+ export async function moveLocalCaAuthorityToBackup(opts = {}) {
682
+ assertDestructiveCertOpAllowed('renewRootMoveBackup');
683
+
684
+ const authorityDir = path.resolve(
685
+ opts.authorityDir || getCaddyPkiAuthoritiesLocalDir()
686
+ );
687
+ const pathExists = opts.pathExists || ((p) => fs.pathExists(p));
688
+ if (!(await pathExists(authorityDir))) {
689
+ return {
690
+ ok: false,
691
+ error: `CA authority directory not found: ${authorityDir}`,
692
+ };
693
+ }
694
+
695
+ const lstat = opts.lstat || ((p) => fs.lstat(p));
696
+ try {
697
+ const stats = await lstat(authorityDir);
698
+ if (stats.isSymbolicLink()) {
699
+ return { ok: false, error: 'Refusing to move a symlinked CA authority path.' };
700
+ }
701
+ if (!stats.isDirectory()) {
702
+ return { ok: false, error: 'CA authority path is not a directory.' };
703
+ }
704
+ } catch (error) {
705
+ return {
706
+ ok: false,
707
+ error: `Could not lstat CA authority path: ${
708
+ error instanceof Error ? error.message : String(error)
709
+ }`,
710
+ };
711
+ }
712
+
713
+ const now = opts.now || new Date();
714
+ const stamp = now
715
+ .toISOString()
716
+ .replace(/[:.]/g, '-')
717
+ .replace(/Z$/, 'Z');
718
+ const backupDir = `${authorityDir}.backup.${stamp}`;
719
+ if (await pathExists(backupDir)) {
720
+ return { ok: false, error: `Backup path already exists: ${backupDir}` };
721
+ }
722
+
723
+ const move = opts.move || ((src, dest) => fs.move(src, dest));
724
+ try {
725
+ await move(authorityDir, backupDir);
726
+ } catch (error) {
727
+ return {
728
+ ok: false,
729
+ error: error instanceof Error ? error.message : String(error),
730
+ };
731
+ }
732
+
733
+ return { ok: true, authorityDir, backupDir };
734
+ }
735
+
736
+ /** Delete one orphaned keychain cert by SHA-1. */
737
+ export async function deleteKeychainCertificateBySha1(opts) {
738
+ assertDestructiveCertOpAllowed('deleteKeychainItemBySha1');
739
+ const built = buildSecurityDeleteCertificateArgs(
740
+ opts.sha1,
741
+ opts.keychainPath
742
+ );
743
+ if (!built.ok) return built;
744
+
745
+ const exec = opts.exec || defaultExec;
746
+ try {
747
+ await exec('security', built.args);
748
+ return { ok: true, args: built.args };
749
+ } catch (error) {
750
+ return {
751
+ ok: false,
752
+ error: error instanceof Error ? error.message : String(error),
753
+ args: built.args,
754
+ };
755
+ }
756
+ }
757
+
758
+ /** Server names with handshake status fail (ignores skip/ok/warn). */
759
+ export function domainsNeedingSiteCertRenewal(handshakes = []) {
760
+ return handshakes
761
+ .filter((hs) => hs && hs.status === 'fail' && hs.servername)
762
+ .map((hs) => hs.servername);
763
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Validate and normalize the Stagepass live-reload event-server port.
3
+ * Only integers in 1024..65535 may be written into a Caddyfile.
4
+ */
5
+
6
+ /**
7
+ * @param {unknown} port
8
+ * @returns {port is number}
9
+ */
10
+ export function isValidDevPort(port) {
11
+ return (
12
+ typeof port === 'number' &&
13
+ Number.isInteger(port) &&
14
+ port >= 1024 &&
15
+ port <= 65535
16
+ );
17
+ }
18
+
19
+ /**
20
+ * Coerce a stored/unknown value to a valid port, or null.
21
+ * @param {unknown} value
22
+ * @returns {number|null}
23
+ */
24
+ export function normalizeDevPort(value) {
25
+ if (typeof value === 'string' && /^\d+$/.test(value)) {
26
+ value = Number(value);
27
+ }
28
+ return isValidDevPort(value) ? value : null;
29
+ }
30
+
31
+ /**
32
+ * Whether a PID looks alive (best-effort; signal 0).
33
+ * @param {unknown} pid
34
+ * @returns {boolean}
35
+ */
36
+ export function isPidAlive(pid) {
37
+ const n = typeof pid === 'string' && /^\d+$/.test(pid) ? Number(pid) : pid;
38
+ if (typeof n !== 'number' || !Number.isInteger(n) || n <= 0) return false;
39
+ try {
40
+ process.kill(n, 0);
41
+ return true;
42
+ } catch {
43
+ return false;
44
+ }
45
+ }
@@ -1,13 +1,21 @@
1
1
  /**
2
- * Doctor checks: declared modules vs Stagepass scripts on the live site.
3
- * Read-only public GET; HTML parsed, never executed.
2
+ * Doctor checks for the current project folder: declared modules in
3
+ * stagepass.json vs. the Stagepass scripts the live Webflow site loads,
4
+ * plus a PHP check when the project opts into PHP.
5
+ * Read-only: one public GET of the live page, parsed and never executed.
4
6
  */
5
7
 
6
8
  import path from 'node:path';
7
9
  import fs from 'fs-extra';
8
10
  import { detectSite, describeDetection } from './site-detect.js';
9
11
  import { formatModules, sameModules } from './project-modules.js';
10
- import { declaredModules, readStagepassJson, resolveProjectOrigin } from './project-sync.js';
12
+ import {
13
+ declaredModules,
14
+ phpFromStagepassConfig,
15
+ readStagepassJson,
16
+ resolveProjectOrigin,
17
+ } from './project-sync.js';
18
+ import { resolveCommand } from './exec.js';
11
19
 
12
20
  /**
13
21
  * @param {object} [opts]
@@ -15,6 +23,8 @@ import { declaredModules, readStagepassJson, resolveProjectOrigin } from './proj
15
23
  * @param {boolean} [opts.skipSite]
16
24
  * @param {(site: string) => Promise<any>} [opts.detectSite]
17
25
  * @param {Function} [opts.loadProjects]
26
+ * @param {typeof resolveCommand} [opts.resolveCommand]
27
+ * @param {Function} [opts.exec]
18
28
  * @returns {Promise<{ id: string, status: 'ok'|'warn'|'fail'|'info', message: string, detail?: string }[]>}
19
29
  */
20
30
  export async function runProjectSiteChecks(opts = {}) {
@@ -39,8 +49,43 @@ export async function runProjectSiteChecks(opts = {}) {
39
49
  checks.push({ id: 'project.modules', status: 'ok', message: `Declared modules: ${formatModules(declared)}` });
40
50
  }
41
51
 
52
+ const php = phpFromStagepassConfig(sp.data);
53
+ if (php === false) {
54
+ checks.push({
55
+ id: 'project.php',
56
+ status: 'info',
57
+ message: 'PHP is off for this project (no php_fastcgi on link)',
58
+ });
59
+ } else if (php === true) {
60
+ const resolve = opts.resolveCommand || resolveCommand;
61
+ const phpPath = await resolve('php', opts.exec);
62
+ const apiDir = path.join(cwd, 'api');
63
+ const apiOk = await fs.pathExists(apiDir);
64
+ if (!phpPath) {
65
+ checks.push({
66
+ id: 'project.php',
67
+ status: 'fail',
68
+ message: 'Project enables PHP but php was not found on PATH',
69
+ detail: 'Install PHP (stagepass setup) or set "php": false in stagepass.json',
70
+ });
71
+ } else if (!apiOk) {
72
+ checks.push({
73
+ id: 'project.php',
74
+ status: 'warn',
75
+ message: `PHP enabled (php=${phpPath}) but api/ folder is missing`,
76
+ detail: 'Create api/ for handlers served via php_fastcgi',
77
+ });
78
+ } else {
79
+ checks.push({
80
+ id: 'project.php',
81
+ status: 'ok',
82
+ message: `PHP enabled for this project (php=${phpPath}, api/ present)`,
83
+ });
84
+ }
85
+ }
86
+
42
87
  if (opts.skipSite) return checks;
43
- const found = await resolveProjectOrigin(cwd, sp.data, { loadProjects: opts.loadProjects, log: opts.log });
88
+ const found = await resolveProjectOrigin(cwd, sp.data, { loadProjects: opts.loadProjects });
44
89
  if (!found) {
45
90
  checks.push({
46
91
  id: 'project.site',
@@ -70,10 +115,21 @@ export async function runProjectSiteChecks(opts = {}) {
70
115
  });
71
116
  return checks;
72
117
  }
118
+ let siteMsg =
119
+ det.loader.cdn === 'self'
120
+ ? `Live site ${found.origin} loads a self-hosted @stagepass/loader`
121
+ : `Live site ${found.origin} loads @stagepass/loader@${det.loader.version}`;
122
+ if (
123
+ det.loader.cdn === 'self' &&
124
+ det.loader.version &&
125
+ det.loader.version !== 'latest'
126
+ ) {
127
+ siteMsg += ` (version ${det.loader.version})`;
128
+ }
73
129
  checks.push({
74
130
  id: 'project.site',
75
131
  status: 'ok',
76
- message: `Live site ${found.origin} loads @stagepass/loader@${det.loader.version}`,
132
+ message: siteMsg,
77
133
  detail: describeDetection(det),
78
134
  });
79
135
  if (declared && !sameModules(declared, det.list)) {
package/src/lib/doctor.js CHANGED
@@ -15,6 +15,7 @@ import {
15
15
  CHROME_LNA_HINT,
16
16
  findUnpinnedCdnSnippets,
17
17
  RECOMMENDED_CDN_SNIPPETS,
18
+ scanProjectUnpinnedCdn,
18
19
  } from './cdn-snippets.js';
19
20
 
20
21
  /**
@@ -419,7 +420,7 @@ export async function runDoctor(opts = {}) {
419
420
  checks.push(
420
421
  check(
421
422
  `certs.tls.${hs.servername}`,
422
- hs.status,
423
+ hs.status === 'skip' ? 'info' : hs.status,
423
424
  hs.reason || `TLS check for ${hs.servername}`
424
425
  )
425
426
  );
@@ -461,7 +462,7 @@ export async function runDoctor(opts = {}) {
461
462
  );
462
463
  }
463
464
 
464
- // CDN snippets (Stagepass-recommended; do not scan user sites)
465
+ // CDN snippets: canonical docs + current project snippet files (read-only)
465
466
  const snippets = opts.cdnSnippets || RECOMMENDED_CDN_SNIPPETS;
466
467
  const unpinned = findUnpinnedCdnSnippets(snippets);
467
468
  if (!unpinned.ok) {
@@ -469,7 +470,7 @@ export async function runDoctor(opts = {}) {
469
470
  check(
470
471
  'cdn',
471
472
  'warn',
472
- 'Recommended CDN snippets include @latest (prefer major pin @2)',
473
+ 'Recommended CDN snippets include unpinned refs (@latest, @1, or bare package; prefer @2)',
473
474
  unpinned.offenders.join(', ')
474
475
  )
475
476
  );
@@ -478,11 +479,54 @@ export async function runDoctor(opts = {}) {
478
479
  check(
479
480
  'cdn',
480
481
  'ok',
481
- 'Recommended CDN snippets use a pinned major (@2), not @latest'
482
+ 'Recommended CDN snippets use a pinned major (@2), not @latest/@1/bare'
482
483
  )
483
484
  );
484
485
  }
485
486
 
487
+ if (opts.projectCdnScan !== false) {
488
+ try {
489
+ const projectCdn =
490
+ opts.projectCdnResult ||
491
+ (await scanProjectUnpinnedCdn({
492
+ cwd: opts.cwd,
493
+ files: opts.projectCdnFiles,
494
+ pathExists,
495
+ readFile,
496
+ }));
497
+ if (!projectCdn.ok) {
498
+ const detail = projectCdn.offenders
499
+ .map((o) => `${o.file}: ${o.match}`)
500
+ .join('; ');
501
+ checks.push(
502
+ check(
503
+ 'cdn.project',
504
+ 'warn',
505
+ 'Project files contain unpinned Stagepass CDN URLs (@latest, @1, or bare; prefer @2)',
506
+ detail
507
+ )
508
+ );
509
+ } else {
510
+ checks.push(
511
+ check(
512
+ 'cdn.project',
513
+ 'ok',
514
+ 'Project snippet files use pinned Stagepass CDN URLs (or none found)'
515
+ )
516
+ );
517
+ }
518
+ } catch (error) {
519
+ checks.push(
520
+ check(
521
+ 'cdn.project',
522
+ 'warn',
523
+ 'Could not scan project files for CDN pins',
524
+ error instanceof Error ? error.message : String(error)
525
+ )
526
+ );
527
+ }
528
+ }
529
+
486
530
  hints.push(CHROME_LNA_HINT);
487
531
 
488
532
  // Current project folder: declared modules vs. live site (read-only GET)