@stagepass/cli 2.5.0 → 2.7.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.
- package/README.md +11 -10
- package/package.json +2 -2
- package/src/cli.js +1 -0
- package/src/commands/link.js +6 -0
- package/src/commands/new.js +30 -3
- package/src/commands/upgrade.js +42 -24
- package/src/lib/ai-guide.js +34 -5
- package/src/lib/build-script-upgrade.js +1 -1
- package/src/lib/cdn-base.js +74 -8
- package/src/lib/cdn-snippets.js +14 -11
- package/src/lib/doctor.js +3 -3
- package/src/lib/origins.js +71 -18
- package/src/lib/package-versions.js +2 -2
- package/src/lib/project-sync.js +16 -0
- package/src/lib/registry.js +1 -1
- package/src/lib/scaffold.js +9 -1
- package/src/lib/site-detect.js +13 -1
- package/src/lib/snippets.js +104 -27
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ The CLI sets up and manages the local Stagepass infrastructure (`.sp` domains, C
|
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
9
|
-
Published CLI 2.
|
|
9
|
+
Published CLI 2.5.0 requires Node.js **20.17+** (`engines.node`: `>=20.17.0`) on **macOS** with Homebrew, because `@inquirer/prompts@8` requires it. Node 18 is no longer supported; stay on `@stagepass/cli@2.2.7` if you must remain on Node 18. Development and CI use Node 22 or 24.
|
|
10
10
|
|
|
11
11
|
```bash
|
|
12
12
|
npm install -g @stagepass/cli@2
|
|
@@ -21,7 +21,7 @@ npx @stagepass/cli@2 setup
|
|
|
21
21
|
## Requirements
|
|
22
22
|
|
|
23
23
|
- **macOS** (system commands refuse other platforms with exit code 1; this is not a breaking change because those commands never worked off macOS)
|
|
24
|
-
- Published CLI 2.
|
|
24
|
+
- Published CLI 2.5.0: Node.js `>=20.17.0`. Use Node 22 or 24 for local development and CI
|
|
25
25
|
- Homebrew
|
|
26
26
|
|
|
27
27
|
`stagepass --version` and `stagepass --help` work on any platform. For tests/CI only, set `STAGEPASS_SKIP_PLATFORM_CHECK=1` to bypass the macOS guard (not for production use).
|
|
@@ -73,7 +73,7 @@ All commands support `-v, --verbose` where applicable.
|
|
|
73
73
|
### Doctor / certificates / autostart
|
|
74
74
|
|
|
75
75
|
- `doctor` and `certs check` are read-only. They never delete keychain items or certificate files.
|
|
76
|
-
-
|
|
76
|
+
- Unreleased CLI changes generate Webflow snippets on `https://cdn.stagepass.one` with the major aliases `loader@2` / `modules@2` (no `data-stagepass-version`). Exact pins remain documented. `stagepass new --cdn jsdelivr` keeps the jsDelivr major pin `@2`. Doctor warns on unpinned CDN URLs on that host, on jsDelivr, and on existing unpkg (`@latest`, bare `@1`, or unversioned `@stagepass/loader` / `@stagepass/modules` in recommended snippets and in the current project's `README.md`, `stagepass.json`, and `*.html` files directly in the project root and in `snippets/`; non-recursive, regular files ≤ 1 MB, symlinks skipped).
|
|
77
77
|
- `certs renew` is opt-in and confirmation-gated. Site repair only deletes `certificates/local/<linked-domain>` after checks fail. `--root` moves the CA folder to a timestamped backup (never deletes; needs two interactive confirmations without `--yes`, or `--yes --i-understand-root-renewal`). `--yes` alone always aborts for `--root` (TTY or not). Do not combine `--root` with `--remove-orphans`; run them as separate commands. Orphans are removed only by SHA-1 via `renew --remove-orphans`.
|
|
78
78
|
- Chrome may require Local Network Access permission for public HTTPS pages that load `https://*.sp` assets.
|
|
79
79
|
- 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, may notify, and exits `0` so launchd KeepAlive does not restart-loop. Interactive `start` confirms before signalling any non-caddy listener (name + PID; SIGTERM then optional SIGKILL). Own processes are signalled without elevated rights first; `sudo` only when needed after confirmation. There is no standby `sudo -v`.
|
|
@@ -122,12 +122,13 @@ Scaffold a project with flags for every choice (interactive prompts only on a TT
|
|
|
122
122
|
| `--remote <url>` | Set `origin` after git init (rejects URLs with embedded credentials). |
|
|
123
123
|
| `--cursor-rule` | Write `.cursor/rules/stagepass.mdc` even when the target has no `.cursor/` directory. Without this flag the rule is written only if `.cursor/` already exists. |
|
|
124
124
|
| `--install` / `--no-install` | Run `npm install` (default: no). |
|
|
125
|
+
| `--cdn stagepass\|jsdelivr` | CDN for generated Webflow snippets, stored as `cdn` in `stagepass.json` (default: `stagepass`, major alias `@2` on `https://cdn.stagepass.one`). The wizard does not ask; pass `--cdn jsdelivr` to opt in. `stagepass upgrade` reads it back. |
|
|
125
126
|
| `-y, --yes` | Non-interactive; use defaults for omitted flags. |
|
|
126
127
|
| `--dry-run` | Print the file plan without writing. |
|
|
127
128
|
|
|
128
|
-
The name must be DNS-safe (lowercase `a-z`, `0-9`, hyphens; 1 to 63 chars; no leading/trailing hyphen). Existing files are never overwritten. Generated projects include `scripts/build.mjs` (content-hashed `dist/` + SRI `integrity` in `manifest.json`), scripts `build` / `watch` / `dev` (`dev` aliases `watch`), Webflow head/footer snippets (
|
|
129
|
+
The name must be DNS-safe (lowercase `a-z`, `0-9`, hyphens; 1 to 63 chars; no leading/trailing hyphen). Existing files are never overwritten. Generated projects include `scripts/build.mjs` (content-hashed `dist/` + SRI `integrity` in `manifest.json`), scripts `build` / `watch` / `dev` (`dev` aliases `watch`), Webflow head/footer snippets (Stagepass CDN first, major alias `@2`, no `data-stagepass-version`; pass `--cdn jsdelivr` for the jsDelivr alternative), `stagepass.json`, `AGENTS.stagepass.md` (the CLI-owned guide), a short pointer in `AGENTS.md`, and a `.gitignore`. `.cursor/rules/stagepass.mdc` (`alwaysApply: true`, pointer to `@AGENTS.stagepass.md`) is written only when the target already has a `.cursor/` directory or you pass `--cursor-rule`. `@stagepass/loader` / `@stagepass/modules` are added as `^2` (same major as the CDN pin `@2`; npm installs the newest published 2.x). Prefer `stagepass build`, `stagepass watch` and `stagepass dev` over calling the npm scripts directly. Per-module types are written only when the published or installed `@stagepass/modules` ships them (2.2.0 and later); otherwise `types` lists the umbrella `@stagepass/modules`.
|
|
129
130
|
|
|
130
|
-
Interactively (macOS), `new` runs a read-only `doctor` preflight and can offer `stagepass setup` if the local stack looks incomplete (never automatic, never under `--yes` / no-TTY, never sudo by itself). Without a TTY (or with `--yes`) it uses `--site-modules`, then `--site` detection, else `[]` with a hint. The interactive wizard
|
|
131
|
+
Interactively (macOS), `new` runs a read-only `doctor` preflight and can offer `stagepass setup` if the local stack looks incomplete (never automatic, never under `--yes` / no-TTY, never sudo by itself). Without a TTY (or with `--yes`) it uses `--site-modules`, then `--site` detection, else `[]` with a hint. The interactive wizard defaults to the Stagepass CDN (no CDN question; pass `--cdn jsdelivr` to opt in) and asks whether to enable PHP unless `--php` / `--no-php` was passed. Staging / production prompts accept pasted `http(s)://` URLs (normalised to the hostname). `--staging` / `--production` and `link` reading `origin` / `production` from `stagepass.json` share that normalisation.
|
|
131
132
|
|
|
132
133
|
### PHP
|
|
133
134
|
|
|
@@ -159,7 +160,7 @@ location ~* /\.(?!well-known\/) {
|
|
|
159
160
|
|
|
160
161
|
Both rules were tested on 12 November 2026 on php:8.2-apache (`AllowOverride All`, `a2enmod rewrite`) and on nginx 1.27 with php:8.2-fpm. `/.env`, `/.php/config.php`, `/api/.env.example`, and `/.git/HEAD` returned HTTP 403, with no secret or config leak. `/api/action.php?action=ping` returned HTTP 200, `{"status":"success","data":{"pong":true},"message":null}`. `/.well-known/test.txt` returned HTTP 200, body `well-known-ok`. `/.well-known/` as a directory with no index file returned HTTP 403 on both servers (no DirectoryIndex). Visible files under `/.well-known/` stay reachable. CLI 2.4.0 and older still need these rules added by hand. Since 2.4.1 the Apache rule ships in the PHP scaffold, and `stagepass upgrade` writes a missing project `.htaccess` when `"php": true` ([quYArF43](https://trello.com/c/quYArF43)). nginx still needs the snippet on the host.
|
|
161
162
|
|
|
162
|
-
`stagepass dev` / `watch` serve PHP from the project root, so edits show up on the next request. When `"php": true`, `stagepass dev` also watches `api/` and `.php/` and reloads the browser on that same live-reload stream and debounce as `dist/`. It ignores `.env`, `.php/.env`, `.php/rate-limit/`, logs, pid files, key, certificate, and database files (`.pem`, `.key`, `.p12`, `.pfx`, `.crt`, `.cer`, `.sqlite`, `.db`), and editor temp files (`~`, `.swp`, `.DS_Store`). A missing `api/` or `.php/` does not stop the command. The start log names those directories. Without `"php": true` live reload stays on the output directory. From the folder that contains `api/`, `php -S 127.0.0.1:8080 -t .` matches `/api/action.php`. `php -S` does not apply Caddy's hidden-path 404. Do not point it at a folder that already contains a real `.env`. Prefer `stagepass dev` or the linked `.sp` domain. `sp.resolveLocalUrl` returns a URL only during an active `.sp` session. On Webflow, `window.location.origin` is the Webflow host, which does not run PHP. Fetch the absolute PHP host, for example `https://php.example.com/api/action.php`. `rate_limit_allows()` logs storage faults (directory, file, `flock`, or a thrown error). The response is HTTP 503, JSend `error`, `Retry-After: 60`, and no internals, unless `APP_ENV` is `local`, `development`, or `dev` (trimmed, any case). Empty, unset, and every other value stay closed. A limit hit stays HTTP 429. `client_ip()` uses `REMOTE_ADDR` unless that peer is in `TRUSTED_PROXIES`, then reads `TRUSTED_PROXY_HEADER` (`x-forwarded-for` or RFC 7239 `forwarded`) from right to left. This applies to projects created with CLI 2.5.0. CLI 2.4.1 and older stay fail-open and use only `REMOTE_ADDR`. `stagepass upgrade` does not change `api/`. Copy `api/lib/security.php`, `api/lib/request.php`, `api/lib/config.php`, `.php/config.php`, and `api/action.php` from a new scaffold, or re-scaffold. [sgt7wKlT](https://trello.com/c/sgt7wKlT). `stagepass upgrade` does not add the `api/` or `.php/` boilerplate. When `"php": true` and the project root has no `.htaccess`, it writes the shipped template (same bytes as `stagepass new --php`). An existing `.htaccess` is left unchanged. If that file has no `RewriteRule "(^|/)\." - [F]` line, upgrade prints a hint and still exits 0. CLI 2.4.0 and older do not write that file. The website guide is live at [https://stagepass.one/docs/php/](https://stagepass.one/docs/php/) (source outline: [docs/php.md](https://github.com/
|
|
163
|
+
`stagepass dev` / `watch` serve PHP from the project root, so edits show up on the next request. When `"php": true`, `stagepass dev` also watches `api/` and `.php/` and reloads the browser on that same live-reload stream and debounce as `dist/`. It ignores `.env`, `.php/.env`, `.php/rate-limit/`, logs, pid files, key, certificate, and database files (`.pem`, `.key`, `.p12`, `.pfx`, `.crt`, `.cer`, `.sqlite`, `.db`), and editor temp files (`~`, `.swp`, `.DS_Store`). A missing `api/` or `.php/` does not stop the command. The start log names those directories. Without `"php": true` live reload stays on the output directory. From the folder that contains `api/`, `php -S 127.0.0.1:8080 -t .` matches `/api/action.php`. `php -S` does not apply Caddy's hidden-path 404. Do not point it at a folder that already contains a real `.env`. Prefer `stagepass dev` or the linked `.sp` domain. `sp.resolveLocalUrl` returns a URL only during an active `.sp` session. On Webflow, `window.location.origin` is the Webflow host, which does not run PHP. Fetch the absolute PHP host, for example `https://php.example.com/api/action.php`. `rate_limit_allows()` logs storage faults (directory, file, `flock`, or a thrown error). The response is HTTP 503, JSend `error`, `Retry-After: 60`, and no internals, unless `APP_ENV` is `local`, `development`, or `dev` (trimmed, any case). Empty, unset, and every other value stay closed. A limit hit stays HTTP 429. `client_ip()` uses `REMOTE_ADDR` unless that peer is in `TRUSTED_PROXIES`, then reads `TRUSTED_PROXY_HEADER` (`x-forwarded-for` or RFC 7239 `forwarded`) from right to left. This applies to projects created with CLI 2.5.0. CLI 2.4.1 and older stay fail-open and use only `REMOTE_ADDR`. `stagepass upgrade` does not change `api/`. Copy `api/lib/security.php`, `api/lib/request.php`, `api/lib/config.php`, `.php/config.php`, and `api/action.php` from a new scaffold, or re-scaffold. [sgt7wKlT](https://trello.com/c/sgt7wKlT). `stagepass upgrade` does not add the `api/` or `.php/` boilerplate. When `"php": true` and the project root has no `.htaccess`, it writes the shipped template (same bytes as `stagepass new --php`). An existing `.htaccess` is left unchanged. If that file has no `RewriteRule "(^|/)\." - [F]` line, upgrade prints a hint and still exits 0. CLI 2.4.0 and older do not write that file. The website guide is live at [https://stagepass.one/docs/php/](https://stagepass.one/docs/php/) (source outline: [docs/php.md](https://github.com/stagepass-one/os/blob/master/docs/php.md)).
|
|
163
164
|
|
|
164
165
|
### Declared modules (`stagepass.json`)
|
|
165
166
|
|
|
@@ -180,7 +181,7 @@ The legacy boolean `"modules": true|false` is still read; `upgrade` replaces it
|
|
|
180
181
|
|
|
181
182
|
`new --site`, `upgrade` and `doctor` read the modules from the live site: one public `GET` of the origin, https only, no cookies or auth headers, about 5 s timeout, a size cap, at most 3 redirects (all https). Only `<script src>` attributes are parsed with a regex (HTML comments ignored); nothing is executed. Recognised:
|
|
182
183
|
|
|
183
|
-
- CDN (`cdn.jsdelivr.net/npm/`
|
|
184
|
+
- the Stagepass CDN (`cdn.stagepass.one`) first: full file paths such as `/loader@2.5.1/loader.min.js` and short aliases such as `/loader@2.5.1` (no `/dist/` segment). jsDelivr (`cdn.jsdelivr.net/npm/`) and existing unpkg (`unpkg.com/`) tags are still recognised so current sites keep working: full `/dist/{loader,inject,cookies,maintenance,all}(.min).js` paths, any version (`@2`, `@2.0.0`, none), and package-root URLs such as `…/@stagepass/loader@2` or `…/@stagepass/modules@2` (optional trailing slash / query). Package-root maps from each package’s `main` field (loader → `loader`, modules → `all`); there is no `unpkg` / `jsdelivr` / `exports` override in those packages. Recommended new embeds use `https://cdn.stagepass.one` (full file path, no `/dist/` segment).
|
|
184
185
|
- Self-hosted: a Stagepass build filename under a `/stagepass/` path segment (relative or other-origin absolute), a relative `…/@stagepass/…` path (e.g. copied from `node_modules`), or the same filename on a `<script>` that also has a `data-stagepass-*` attribute; renamed loader files that carry a loader-config attribute (`data-stagepass-version`, `data-stagepass-live-src`, …). Result `cdn` is `self`. Bare `loader.js` / `all.min.js` from other libraries without a Stagepass hint are ignored. Absolute URLs on foreign hosts that only mimic an `@stagepass` CDN path (no `/stagepass/` segment and no data attribute) are ignored.
|
|
185
186
|
|
|
186
187
|
Still not recognised: tags without `src`, `data-src` only, other hosts without a Stagepass hint, and module ids that cannot be inferred from the filename. `upgrade` syncs the detected modules list into the project; it does not rewrite self-hosted embeds to CDN URLs (printed Webflow snippets remain the recommended CDN form). The npm dependency in `package.json` is only a hint.
|
|
@@ -199,7 +200,7 @@ Still not recognised: tags without `src`, `data-src` only, other hosts without a
|
|
|
199
200
|
|
|
200
201
|
`upgrade` bumps `@stagepass/*` in `package.json`, then resolves the modules list (`--site-modules`, else live detection, confirmed interactively; if the site is unreachable or no origin is known it asks; without a TTY it keeps the existing list or `[]` and prints a hint). It then syncs the project:
|
|
201
202
|
|
|
202
|
-
- `stagepass.json`: writes the `modules` list.
|
|
203
|
+
- `stagepass.json`: writes the `modules` list. Reads `cdn` (`stagepass` or `jsdelivr`; missing or unknown values use the Stagepass CDN) so `AGENTS.stagepass.md` and the printed snippets share that host and one sanitized loader pin.
|
|
203
204
|
- `AGENTS.stagepass.md`: created when missing. Rewritten when the managed hash still matches and the generated text changed. A hand edit (hash mismatch, or no `stagepass:managed` header) is replaced only with `--yes` or a TTY confirmation (default yes). Without a TTY and without `--yes`, the file stays and the CLI prints a hint that names `--yes`. A second run writes nothing when the file is already current. A symlink is left unchanged.
|
|
204
205
|
- `AGENTS.md`: created if missing (title plus the short pointer). Otherwise only the pointer between the markers is replaced, or appended when there are none. Text outside the markers stays byte for byte, including older generated sections. Upgrade prints a hint when those older sections are still outside the markers. Broken markers are left alone with a hint.
|
|
205
206
|
- `.cursor/rules/stagepass.mdc`: not created unless `.cursor/` already exists or `--cursor-rule` is set. An existing rule is never deleted. With stagepass markers, only the managed block is refreshed (`alwaysApply: true`, pointer to `@AGENTS.stagepass.md`). The previous generated frontmatter (`globs: src/**`, `alwaysApply: false`) is updated when it is still unchanged. A rule without markers is left alone. `stagepass doctor` does not warn about a missing rule when `.cursor/` is absent. When `.cursor/` exists, a missing or stale rule is a warning.
|
|
@@ -218,7 +219,7 @@ Since 2.5.0, when the editor reports `Cannot find name 'sp'` and the page still
|
|
|
218
219
|
2. `npm install`
|
|
219
220
|
3. In the editor command palette: `TypeScript: Restart TS Server`.
|
|
220
221
|
|
|
221
|
-
Every change is printed as `file: action` (unchanged files are not listed; skipped files appear as hints). `npm install` is printed, not run.
|
|
222
|
+
Every change is printed as `file: action` (unchanged files are not listed; skipped files appear as hints). `npm install` is printed, not run. Default snippets use the Stagepass CDN major alias `@2` (no jsDelivr alternative line in CLI output). With `"cdn": "jsdelivr"` the snippets use the jsDelivr major pin `@2` and an optional exact pin note. A concrete `production` host in `stagepass.json` fills footer `data-src` / `data-href`.
|
|
222
223
|
|
|
223
224
|
### Domain argument (`link` / `unlink`)
|
|
224
225
|
|
|
@@ -349,4 +350,4 @@ The v3 block needs Caddy 2.9 or newer (`brew upgrade caddy`). Homebrew does not
|
|
|
349
350
|
|
|
350
351
|
## Repository
|
|
351
352
|
|
|
352
|
-
- Docs and full setup: [stagepass repository](https://github.com/
|
|
353
|
+
- Docs and full setup: [stagepass repository](https://github.com/stagepass-one/os)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stagepass/cli",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0",
|
|
4
4
|
"description": "Local Development Orchestrator for Webflow",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "bin/index.js",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
],
|
|
36
36
|
"repository": {
|
|
37
37
|
"type": "git",
|
|
38
|
-
"url": "https://github.com/
|
|
38
|
+
"url": "https://github.com/stagepass-one/os.git",
|
|
39
39
|
"directory": "packages/cli"
|
|
40
40
|
},
|
|
41
41
|
"license": "MIT",
|
package/src/cli.js
CHANGED
|
@@ -401,6 +401,7 @@ export function createProgram(deps = {}) {
|
|
|
401
401
|
.option('--cursor-rule', 'Write .cursor/rules/stagepass.mdc even when .cursor/ is absent')
|
|
402
402
|
.option('--install', 'Run npm install after scaffolding')
|
|
403
403
|
.option('--no-install', 'Do not run npm install (default)')
|
|
404
|
+
.option('--cdn <host>', 'CDN for Webflow snippets: stagepass (default) or jsdelivr')
|
|
404
405
|
.option('-y, --yes', 'Non-interactive; accept defaults for omitted flags')
|
|
405
406
|
.option('--dry-run', 'Print the file plan without writing')
|
|
406
407
|
.option('-v, --verbose', 'Show detailed output')
|
package/src/commands/link.js
CHANGED
|
@@ -85,6 +85,9 @@ export async function link(domain, options = {}, deps = {}) {
|
|
|
85
85
|
return 1;
|
|
86
86
|
}
|
|
87
87
|
originsFromFlags = check.origins;
|
|
88
|
+
for (const host of check.normalised || []) {
|
|
89
|
+
log(`Using ${host}`);
|
|
90
|
+
}
|
|
88
91
|
for (const entry of check.origins) {
|
|
89
92
|
if (isBroadWebflowWildcard(entry)) {
|
|
90
93
|
log(
|
|
@@ -102,6 +105,9 @@ export async function link(domain, options = {}, deps = {}) {
|
|
|
102
105
|
log(chalk.red(`❌ Invalid --remove-origin: ${check.error}`));
|
|
103
106
|
return 1;
|
|
104
107
|
}
|
|
108
|
+
for (const host of check.normalised || []) {
|
|
109
|
+
log(`Using ${host}`);
|
|
110
|
+
}
|
|
105
111
|
}
|
|
106
112
|
|
|
107
113
|
let allowAllOriginsFlag;
|
package/src/commands/new.js
CHANGED
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
printWebflowSnippets,
|
|
21
21
|
} from '../lib/snippets.js';
|
|
22
22
|
|
|
23
|
-
import { SNIPPET_LOADER_VERSION } from '../lib/cdn-base.js';
|
|
23
|
+
import { SNIPPET_LOADER_VERSION, normalizeCdnChoice } from '../lib/cdn-base.js';
|
|
24
24
|
import { formatModules, normalizeModulesList } from '../lib/project-modules.js';
|
|
25
25
|
import { cursorDirPresent } from '../lib/project-sync.js';
|
|
26
26
|
import { describeDetection, detectSite, normalizeSiteUrl } from '../lib/site-detect.js';
|
|
@@ -81,7 +81,11 @@ export function parseOriginFlag(raw, label) {
|
|
|
81
81
|
if (!check.ok) {
|
|
82
82
|
return { ok: false, error: `Invalid --${label}: ${check.error}` };
|
|
83
83
|
}
|
|
84
|
-
return {
|
|
84
|
+
return {
|
|
85
|
+
ok: true,
|
|
86
|
+
value: check.value,
|
|
87
|
+
...(check.normalised ? { normalised: true } : {}),
|
|
88
|
+
};
|
|
85
89
|
}
|
|
86
90
|
|
|
87
91
|
/**
|
|
@@ -181,6 +185,19 @@ export async function resolveNewOptions(nameArg, options = {}, deps = {}) {
|
|
|
181
185
|
siteModules = parsed.modules;
|
|
182
186
|
}
|
|
183
187
|
|
|
188
|
+
/** @type {string} */
|
|
189
|
+
let cdn = '';
|
|
190
|
+
if (options.cdn != null) {
|
|
191
|
+
const parsed = normalizeCdnChoice(options.cdn);
|
|
192
|
+
if (!parsed) {
|
|
193
|
+
return {
|
|
194
|
+
ok: false,
|
|
195
|
+
error: 'Invalid --cdn: use stagepass (default) or jsdelivr.',
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
cdn = parsed;
|
|
199
|
+
}
|
|
200
|
+
|
|
184
201
|
/** @type {string} */
|
|
185
202
|
let origin = '';
|
|
186
203
|
/** @type {string} */
|
|
@@ -208,11 +225,13 @@ export async function resolveNewOptions(nameArg, options = {}, deps = {}) {
|
|
|
208
225
|
};
|
|
209
226
|
}
|
|
210
227
|
origin = check.value;
|
|
228
|
+
if (check.normalised) log(`Using ${check.value}`);
|
|
211
229
|
}
|
|
212
230
|
if (options.production != null && String(options.production) !== '') {
|
|
213
231
|
const check = parseOriginFlag(String(options.production), 'production');
|
|
214
232
|
if (!check.ok) return check;
|
|
215
233
|
production = check.value;
|
|
234
|
+
if (check.normalised) log(`Using ${check.value}`);
|
|
216
235
|
} else if (
|
|
217
236
|
Object.prototype.hasOwnProperty.call(options, 'production') &&
|
|
218
237
|
(options.production === '' || options.production == null) &&
|
|
@@ -279,6 +298,7 @@ export async function resolveNewOptions(nameArg, options = {}, deps = {}) {
|
|
|
279
298
|
const check = validateOriginEntry(raw);
|
|
280
299
|
if (check.ok) {
|
|
281
300
|
origin = check.value;
|
|
301
|
+
if (check.normalised) log(`Using ${check.value}`);
|
|
282
302
|
if (isBroadWebflowWildcard(origin)) {
|
|
283
303
|
log(
|
|
284
304
|
chalk.yellow(
|
|
@@ -297,6 +317,7 @@ export async function resolveNewOptions(nameArg, options = {}, deps = {}) {
|
|
|
297
317
|
const check = validateOriginEntry(raw);
|
|
298
318
|
if (check.ok) {
|
|
299
319
|
production = check.value;
|
|
320
|
+
if (check.normalised) log(`Using ${check.value}`);
|
|
300
321
|
if (isBroadWebflowWildcard(production)) {
|
|
301
322
|
log(
|
|
302
323
|
chalk.yellow(
|
|
@@ -328,6 +349,7 @@ export async function resolveNewOptions(nameArg, options = {}, deps = {}) {
|
|
|
328
349
|
else log(chalk.yellow(` ${parsed.error}`));
|
|
329
350
|
}
|
|
330
351
|
}
|
|
352
|
+
// CDN defaults to Stagepass (cdn.stagepass.one). Use --cdn jsdelivr to opt in.
|
|
331
353
|
if (php === undefined) {
|
|
332
354
|
php = await askYesNo(rl, 'Enable PHP for this project?', false);
|
|
333
355
|
}
|
|
@@ -367,6 +389,8 @@ export async function resolveNewOptions(nameArg, options = {}, deps = {}) {
|
|
|
367
389
|
// The npm package (types) follows the declared list; keep the legacy default (included).
|
|
368
390
|
if (siteModules.length > 0) modules = true;
|
|
369
391
|
|
|
392
|
+
if (!cdn) cdn = 'stagepass';
|
|
393
|
+
|
|
370
394
|
// Non-interactive / --yes defaults
|
|
371
395
|
if (!name) {
|
|
372
396
|
return { ok: false, error: 'Project name is required (pass [name] or use a TTY).' };
|
|
@@ -441,6 +465,7 @@ export async function resolveNewOptions(nameArg, options = {}, deps = {}) {
|
|
|
441
465
|
dryRun: options.dryRun === true,
|
|
442
466
|
cursorRule: options.cursorRule === true,
|
|
443
467
|
loaderVersion: deps.packagesVersion || SNIPPET_LOADER_VERSION,
|
|
468
|
+
cdn,
|
|
444
469
|
},
|
|
445
470
|
};
|
|
446
471
|
}
|
|
@@ -835,7 +860,7 @@ export async function createNew(nameArg, options = {}, deps = {}) {
|
|
|
835
860
|
if (!config.install) {
|
|
836
861
|
log(` cd ${path.relative(cwd, targetDir) || '.'} && npm install`);
|
|
837
862
|
}
|
|
838
|
-
log('
|
|
863
|
+
log(' stagepass build');
|
|
839
864
|
if (config.origin || config.production) {
|
|
840
865
|
log(` stagepass link ${config.name}`);
|
|
841
866
|
} else {
|
|
@@ -851,9 +876,11 @@ export async function createNew(nameArg, options = {}, deps = {}) {
|
|
|
851
876
|
const snippets = buildWebflowSnippets({
|
|
852
877
|
version: config.loaderVersion,
|
|
853
878
|
moduleList: config.siteModules,
|
|
879
|
+
production: config.production,
|
|
854
880
|
gitRemote: config.git ? config.remote || '' : '',
|
|
855
881
|
gitBranch: config.git ? 'main' : '',
|
|
856
882
|
projectName: config.name,
|
|
883
|
+
cdn: config.cdn,
|
|
857
884
|
});
|
|
858
885
|
printWebflowSnippets(snippets, log);
|
|
859
886
|
|
package/src/commands/upgrade.js
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
buildWebflowSnippets,
|
|
7
7
|
printWebflowSnippets,
|
|
8
8
|
readSnippetGitRef,
|
|
9
|
+
sanitizeSnippetVersion,
|
|
9
10
|
} from '../lib/snippets.js';
|
|
10
11
|
|
|
11
12
|
import readline from 'node:readline/promises';
|
|
@@ -23,6 +24,7 @@ import {
|
|
|
23
24
|
import { detectSite, normalizeSiteUrl } from '../lib/site-detect.js';
|
|
24
25
|
import {
|
|
25
26
|
applyProjectSync,
|
|
27
|
+
cdnFromStagepassConfig,
|
|
26
28
|
phpFromStagepassConfig,
|
|
27
29
|
planProjectSync,
|
|
28
30
|
readStagepassJson,
|
|
@@ -220,6 +222,8 @@ export function ensureTypeDevDependencies(pkg, modules, specs) {
|
|
|
220
222
|
* without asking. When stagepass.json has `"php": true`
|
|
221
223
|
* and the project root has no `.htaccess`, writes the shipped template.
|
|
222
224
|
* It does not copy `api/` when that boilerplate is missing.
|
|
225
|
+
* `AGENTS.stagepass.md` and the printed Webflow snippets share one sanitized
|
|
226
|
+
* loader pin and the CDN recorded in `stagepass.json` (`stagepass` when missing).
|
|
223
227
|
*
|
|
224
228
|
* @param {object} [options]
|
|
225
229
|
* @param {boolean} [options.dryRun]
|
|
@@ -390,22 +394,8 @@ export async function upgrade(options = {}, deps = {}) {
|
|
|
390
394
|
fromRegistry != null ? fromRegistry : (await installedHasPerModuleTypes(cwd, fse)) === true;
|
|
391
395
|
}
|
|
392
396
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
cwd,
|
|
396
|
-
modules: resolved.modules,
|
|
397
|
-
origin: options.site ? resolved.origin : null,
|
|
398
|
-
pkg: next,
|
|
399
|
-
perModuleTypes,
|
|
400
|
-
interactive,
|
|
401
|
-
assumeYes,
|
|
402
|
-
confirm: confirmFn,
|
|
403
|
-
cursorRule: options.cursorRule === true,
|
|
404
|
-
},
|
|
405
|
-
fse
|
|
406
|
-
);
|
|
407
|
-
|
|
408
|
-
// Refuse an unpublished --version before asking about scripts/build.mjs or writing.
|
|
397
|
+
// One sanitized pin and one CDN for the guide and the printed snippets.
|
|
398
|
+
// Refuse an unpublished --version before asking about project files or writing.
|
|
409
399
|
let loaderPub = '@stagepass/loader' in published ? published['@stagepass/loader'] : undefined;
|
|
410
400
|
const getLoaderPub = async () => {
|
|
411
401
|
if (loaderPub !== undefined) return loaderPub;
|
|
@@ -426,6 +416,38 @@ export async function upgrade(options = {}, deps = {}) {
|
|
|
426
416
|
}
|
|
427
417
|
if (t.resolved && satisfiesSimple(t.resolved, PACKAGES_MAJOR_RANGE)) snippetVersion = t.resolved;
|
|
428
418
|
}
|
|
419
|
+
if (!snippetVersion) {
|
|
420
|
+
snippetVersion = await resolveSnippetLoaderVersion({
|
|
421
|
+
published: await getLoaderPub(),
|
|
422
|
+
cwd,
|
|
423
|
+
bundled: SNIPPET_LOADER_VERSION,
|
|
424
|
+
fse,
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
try {
|
|
428
|
+
snippetVersion = sanitizeSnippetVersion(snippetVersion);
|
|
429
|
+
} catch (err) {
|
|
430
|
+
log(chalk.red(err instanceof Error ? err.message : String(err)));
|
|
431
|
+
return 1;
|
|
432
|
+
}
|
|
433
|
+
const cdn = cdnFromStagepassConfig(sp.data);
|
|
434
|
+
|
|
435
|
+
const plan = await planProjectSync(
|
|
436
|
+
{
|
|
437
|
+
cwd,
|
|
438
|
+
modules: resolved.modules,
|
|
439
|
+
origin: options.site ? resolved.origin : null,
|
|
440
|
+
pkg: next,
|
|
441
|
+
perModuleTypes,
|
|
442
|
+
interactive,
|
|
443
|
+
assumeYes,
|
|
444
|
+
confirm: confirmFn,
|
|
445
|
+
cursorRule: options.cursorRule === true,
|
|
446
|
+
cdn,
|
|
447
|
+
loaderVersion: snippetVersion,
|
|
448
|
+
},
|
|
449
|
+
fse
|
|
450
|
+
);
|
|
429
451
|
|
|
430
452
|
/** @type {{ action: string, from?: string, content?: string, note?: string }} */
|
|
431
453
|
let buildUpgrade = { action: 'skipped' };
|
|
@@ -506,24 +528,20 @@ export async function upgrade(options = {}, deps = {}) {
|
|
|
506
528
|
);
|
|
507
529
|
}
|
|
508
530
|
|
|
509
|
-
if (!snippetVersion) {
|
|
510
|
-
snippetVersion = await resolveSnippetLoaderVersion({
|
|
511
|
-
published: await getLoaderPub(),
|
|
512
|
-
cwd,
|
|
513
|
-
bundled: SNIPPET_LOADER_VERSION,
|
|
514
|
-
fse,
|
|
515
|
-
});
|
|
516
|
-
}
|
|
517
531
|
let snippets;
|
|
518
532
|
try {
|
|
519
533
|
const readGitRef = deps.readGitRef || readSnippetGitRef;
|
|
520
534
|
const gitRef = await readGitRef(cwd);
|
|
535
|
+
const production =
|
|
536
|
+
sp.data && typeof sp.data.production === 'string' ? sp.data.production : '';
|
|
521
537
|
snippets = buildWebflowSnippets({
|
|
522
538
|
version: snippetVersion,
|
|
523
539
|
moduleList: resolved.modules,
|
|
540
|
+
production,
|
|
524
541
|
gitRemote: gitRef && gitRef.gitRemote,
|
|
525
542
|
gitBranch: gitRef && gitRef.gitBranch,
|
|
526
543
|
projectName: pkg.name,
|
|
544
|
+
cdn,
|
|
527
545
|
});
|
|
528
546
|
} catch (err) {
|
|
529
547
|
log(chalk.red(err instanceof Error ? err.message : String(err)));
|
package/src/lib/ai-guide.js
CHANGED
|
@@ -11,6 +11,12 @@ import { createHash } from 'node:crypto';
|
|
|
11
11
|
import { createRequire } from 'node:module';
|
|
12
12
|
import { MODULE_IDS, expandModules, formatModules } from './project-modules.js';
|
|
13
13
|
import { LOADER_VERSION, MODULES_VERSION } from './versions.js';
|
|
14
|
+
import {
|
|
15
|
+
SNIPPET_LOADER_VERSION,
|
|
16
|
+
SNIPPET_MODULES_VERSION,
|
|
17
|
+
normalizeCdnChoice,
|
|
18
|
+
stagepassPackageUrl,
|
|
19
|
+
} from './cdn-base.js';
|
|
14
20
|
|
|
15
21
|
const require = createRequire(import.meta.url);
|
|
16
22
|
export const CLI_VERSION = require('../../package.json').version;
|
|
@@ -85,7 +91,7 @@ if (sp.can('localStorage')) localStorage.setItem('seen', '1');
|
|
|
85
91
|
const MODULE_SECTIONS = {
|
|
86
92
|
inject: `### Module: inject (\`sp.inject\`)
|
|
87
93
|
|
|
88
|
-
Loads extra scripts and stylesheets. Webflow script tag:
|
|
94
|
+
Loads extra scripts and stylesheets. Webflow script tag: \`https://cdn.stagepass.one/modules@2/inject.min.js\` after the loader (exact pin optional: \`modules@${SNIPPET_MODULES_VERSION}/inject.min.js\`).
|
|
89
95
|
|
|
90
96
|
\`\`\`ts
|
|
91
97
|
if (sp.inject) {
|
|
@@ -99,7 +105,7 @@ Argument: one options object, an array of them, or \`{ scripts?, styles? }\`. Re
|
|
|
99
105
|
Options: \`src\` (required), \`type\` (\`'script' \\| 'style'\`), \`stagepass\` (default true: during a session the file is served from the local project via \`localPath\`/\`path\` or the file name; \`false\` always uses \`src\`), \`localPath\`, \`path\`, \`id\`, \`async\`, \`defer\`, \`version\` (adds \`?v=\` in production), \`attributes\`, \`position\` (\`'head' \\| 'body-start' \\| 'body-end' \\| { target, action: 'before' \\| 'after' }\`), \`integrity\`, \`crossorigin\`, \`nonce\`, \`allowedHosts\`.`,
|
|
100
106
|
cookies: `### Module: cookies (\`sp.cookies\`, alias \`sp.cookie\`, plus \`sp.consent\`)
|
|
101
107
|
|
|
102
|
-
Webflow script tag:
|
|
108
|
+
Webflow script tag: \`https://cdn.stagepass.one/modules@2/cookies.min.js\` after the loader (exact pin optional: \`modules@${SNIPPET_MODULES_VERSION}/cookies.min.js\`).
|
|
103
109
|
|
|
104
110
|
\`\`\`ts
|
|
105
111
|
if (sp.cookies) {
|
|
@@ -120,7 +126,7 @@ Write options: \`days\`, \`maxAge\`, \`path\`, \`domain\`, \`secure\`, \`sameSit
|
|
|
120
126
|
Consent: \`allows(category)\`, \`set(fn)\`, \`update()\`.`,
|
|
121
127
|
maintenance: `### Module: maintenance (\`sp.maintenance\`)
|
|
122
128
|
|
|
123
|
-
Webflow script tag:
|
|
129
|
+
Webflow script tag: \`https://cdn.stagepass.one/modules@2/maintenance.min.js\` after the loader (exact pin optional: \`modules@${SNIPPET_MODULES_VERSION}/maintenance.min.js\`; optional attributes \`data-stagepass-maintenance="true"\`, \`data-stagepass-maintenance-title\`, \`data-stagepass-maintenance-text\`).
|
|
124
130
|
|
|
125
131
|
\`\`\`ts
|
|
126
132
|
if (sp.maintenance && !sp.maintenance.isActive()) {
|
|
@@ -352,6 +358,8 @@ function phpLabel(ctx) {
|
|
|
352
358
|
* @param {string | null} ctx.configFile
|
|
353
359
|
* @param {string[]} ctx.types
|
|
354
360
|
* @param {boolean} ctx.modulesDependency
|
|
361
|
+
* @param {string} [ctx.cdn] `stagepass` (default) or `jsdelivr`
|
|
362
|
+
* @param {string} [ctx.loaderVersion] Resolved loader pin used in official snippets
|
|
355
363
|
*/
|
|
356
364
|
export function buildStagepassGuide(ctx) {
|
|
357
365
|
const name = ctx.name || 'project';
|
|
@@ -361,6 +369,27 @@ export function buildStagepassGuide(ctx) {
|
|
|
361
369
|
const openHost = origin || `${linkName}.webflow.io`;
|
|
362
370
|
const configFile = ctx.configFile;
|
|
363
371
|
const types = Array.isArray(ctx.types) ? ctx.types : ['@stagepass/loader'];
|
|
372
|
+
const loaderVersion = ctx.loaderVersion || SNIPPET_LOADER_VERSION;
|
|
373
|
+
const cdnChoice = normalizeCdnChoice(ctx.cdn) || 'stagepass';
|
|
374
|
+
const officialLoaderUrl = stagepassPackageUrl('loader', '@2', 'loader.min.js', {
|
|
375
|
+
cdn: 'stagepass',
|
|
376
|
+
});
|
|
377
|
+
const officialExactLoaderUrl = stagepassPackageUrl(
|
|
378
|
+
'loader',
|
|
379
|
+
`@${loaderVersion}`,
|
|
380
|
+
'loader.min.js',
|
|
381
|
+
{ cdn: 'stagepass' }
|
|
382
|
+
);
|
|
383
|
+
const jsdelivrLoaderUrl = stagepassPackageUrl(
|
|
384
|
+
'loader',
|
|
385
|
+
'@2',
|
|
386
|
+
'loader.min.js',
|
|
387
|
+
{ cdn: 'jsdelivr' }
|
|
388
|
+
);
|
|
389
|
+
const cdnLine =
|
|
390
|
+
cdnChoice === 'jsdelivr'
|
|
391
|
+
? `- **CDN:** This project uses jsDelivr (major pin \`@2\`), for example \`${jsdelivrLoaderUrl}\`. The Stagepass CDN major alias is the alternative (\`${officialLoaderUrl}\`); exact pin example: \`${officialExactLoaderUrl}\`.`
|
|
392
|
+
: `- **CDN:** Stagepass CDN first, major alias \`@2\` (no \`data-stagepass-version\`), for example \`${officialLoaderUrl}\`. Exact pin when needed: \`${officialExactLoaderUrl}\`. jsDelivr is the documented alternative (\`${jsdelivrLoaderUrl}\`).`;
|
|
364
393
|
const parts = [
|
|
365
394
|
`# Stagepass (${name})`,
|
|
366
395
|
'',
|
|
@@ -386,14 +415,14 @@ export function buildStagepassGuide(ctx) {
|
|
|
386
415
|
'- **Session:** `localStorage` key `stagepass_domain`, JSON `{ domain, expires }` (default 12 h).',
|
|
387
416
|
'- **Modules:** separate script tags after `loader.min.js`. This file documents only the modules declared in `stagepass.json`.',
|
|
388
417
|
'- **Runtime:** call `sp` (same object as `window.stagepass`).',
|
|
389
|
-
|
|
418
|
+
cdnLine,
|
|
390
419
|
'',
|
|
391
420
|
'## Safe rules',
|
|
392
421
|
'',
|
|
393
422
|
'1. **No secrets in frontend code.** API keys, tokens, and passwords must never ship in JS or CSS served to the browser.',
|
|
394
423
|
'2. **No `innerHTML` with untrusted data.** Prefer `textContent`, `createElement`, or trusted, sanitized markup.',
|
|
395
424
|
'3. **No `eval` or string-built scripts** with user or CMS input.',
|
|
396
|
-
'4. **
|
|
425
|
+
'4. **Default embeds use the major alias `@2`.** Exact pin on the Stagepass CDN (full path + optional `data-stagepass-version`) when a specific build must load.',
|
|
397
426
|
'5. **Review before publishing.** Read the diff for asset tags, CORS origins, and Webflow Custom Code.',
|
|
398
427
|
'6. **Keep Stagepass tags intact.** Use `data-src` / `data-href` plus `data-stagepass` (and optional `data-stagepass-path`) so production visitors keep production URLs.',
|
|
399
428
|
'7. **Do not commit secrets.** Keep `.env*` out of git.',
|
|
@@ -22,7 +22,7 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
|
22
22
|
export const BUILD_SCRIPT_REL = 'scripts/build.mjs';
|
|
23
23
|
|
|
24
24
|
export const BUILD_SCRIPT_DOC_URL =
|
|
25
|
-
'https://github.com/
|
|
25
|
+
'https://github.com/stagepass-one/os/blob/master/docs/cli.md#upgrade';
|
|
26
26
|
|
|
27
27
|
export const BUILD_SCRIPT_CUSTOM_HINT = [
|
|
28
28
|
'scripts/build.mjs has local edits, so stagepass upgrade left it unchanged.',
|
package/src/lib/cdn-base.js
CHANGED
|
@@ -1,20 +1,86 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Official loader/modules CDN.
|
|
3
|
+
*
|
|
4
|
+
* Default host is https://cdn.stagepass.one: major alias `@2` (short loader URL,
|
|
5
|
+
* no `data-stagepass-version`). Exact pins (full file path + optional
|
|
6
|
+
* `data-stagepass-version`) stay documented. jsDelivr remains an alternative
|
|
7
|
+
* (npm package paths, major pin, `/dist/` segment). Do not recommend unpkg.
|
|
8
|
+
*/
|
|
9
|
+
export const STAGEPASS_CDN_ORIGIN = 'https://cdn.stagepass.one';
|
|
10
|
+
export const STAGEPASS_JSDELIVR_CDN = 'https://cdn.jsdelivr.net/npm';
|
|
11
|
+
/** Default package CDN origin (Stagepass CDN). Prefer stagepassPackageUrl(). */
|
|
12
|
+
export const STAGEPASS_PACKAGE_CDN = STAGEPASS_CDN_ORIGIN;
|
|
3
13
|
|
|
4
14
|
/**
|
|
5
|
-
* Published npm versions for
|
|
15
|
+
* Published npm versions for documented exact-pin examples (loader / modules).
|
|
6
16
|
* Literals only: not read from the CLI package version, and not copied
|
|
7
17
|
* automatically when the monorepo is ahead of npm.
|
|
18
|
+
* Default generated snippets use {@link SNIPPET_MAJOR_PIN}, not these.
|
|
8
19
|
*/
|
|
9
|
-
export const SNIPPET_LOADER_VERSION = '2.5.
|
|
20
|
+
export const SNIPPET_LOADER_VERSION = '2.5.1';
|
|
10
21
|
export const SNIPPET_MODULES_VERSION = '2.2.2';
|
|
22
|
+
export const SNIPPET_MAJOR_PIN = '@2';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @param {unknown} raw
|
|
26
|
+
* @returns {'stagepass' | 'jsdelivr' | null}
|
|
27
|
+
*/
|
|
28
|
+
export function normalizeCdnChoice(raw) {
|
|
29
|
+
const v = String(raw == null ? '' : raw).trim().toLowerCase();
|
|
30
|
+
if (v === 'stagepass') return 'stagepass';
|
|
31
|
+
if (v === 'jsdelivr') return 'jsdelivr';
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Pins used in generated Webflow snippets for a CDN host.
|
|
37
|
+
* Stagepass CDN and jsDelivr both default to the major pin `@2`.
|
|
38
|
+
* @param {unknown} [cdn]
|
|
39
|
+
* @param {{ loaderVersion?: string, modulesVersion?: string, exact?: boolean }} [options]
|
|
40
|
+
* @returns {{ cdn: 'stagepass' | 'jsdelivr', loaderPin: string, modulesPin: string }}
|
|
41
|
+
*/
|
|
42
|
+
export function defaultSnippetPins(cdn, options = {}) {
|
|
43
|
+
const host = normalizeCdnChoice(cdn) || 'stagepass';
|
|
44
|
+
if (host === 'jsdelivr' || options.exact !== true) {
|
|
45
|
+
return {
|
|
46
|
+
cdn: host,
|
|
47
|
+
loaderPin: SNIPPET_MAJOR_PIN,
|
|
48
|
+
modulesPin: SNIPPET_MAJOR_PIN,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
const loaderVersion = options.loaderVersion || SNIPPET_LOADER_VERSION;
|
|
52
|
+
const modulesVersion = options.modulesVersion || SNIPPET_MODULES_VERSION;
|
|
53
|
+
return {
|
|
54
|
+
cdn: host,
|
|
55
|
+
loaderPin: `@${loaderVersion}`,
|
|
56
|
+
modulesPin: `@${modulesVersion}`,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
11
59
|
|
|
12
60
|
/**
|
|
13
61
|
* @param {string} name Package short name (`loader` or `modules`)
|
|
14
|
-
* @param {string} pin CDN pin including `@` (for example `@2`)
|
|
15
|
-
* @param {string} file File under `
|
|
62
|
+
* @param {string} pin CDN pin including `@` (for example `@2` or `@2.5.0`)
|
|
63
|
+
* @param {string} [file] File under the host path (`loader.min.js`). Omitted for
|
|
64
|
+
* the Stagepass CDN major-alias loader short URL (`/loader@2`).
|
|
65
|
+
* @param {{ cdn?: string }} [options]
|
|
16
66
|
* @returns {string}
|
|
17
67
|
*/
|
|
18
|
-
export function stagepassPackageUrl(name, pin, file) {
|
|
19
|
-
|
|
68
|
+
export function stagepassPackageUrl(name, pin, file, options = {}) {
|
|
69
|
+
const cdn = normalizeCdnChoice(options.cdn) || 'stagepass';
|
|
70
|
+
if (cdn === 'jsdelivr') {
|
|
71
|
+
const distFile = file || (name === 'loader' ? 'loader.min.js' : `${name}.min.js`);
|
|
72
|
+
return `${STAGEPASS_JSDELIVR_CDN}/@stagepass/${name}${pin}/dist/${distFile}`;
|
|
73
|
+
}
|
|
74
|
+
// Short major-alias form for the loader: /loader@2 (no /loader.min.js).
|
|
75
|
+
if (
|
|
76
|
+
pin === SNIPPET_MAJOR_PIN &&
|
|
77
|
+
name === 'loader' &&
|
|
78
|
+
(file == null || file === '' || file === 'loader.min.js')
|
|
79
|
+
) {
|
|
80
|
+
return `${STAGEPASS_CDN_ORIGIN}/loader${pin}`;
|
|
81
|
+
}
|
|
82
|
+
if (!file) {
|
|
83
|
+
return `${STAGEPASS_CDN_ORIGIN}/${name}${pin}`;
|
|
84
|
+
}
|
|
85
|
+
return `${STAGEPASS_CDN_ORIGIN}/${name}${pin}/${file}`;
|
|
20
86
|
}
|
package/src/lib/cdn-snippets.js
CHANGED
|
@@ -1,30 +1,33 @@
|
|
|
1
1
|
import fs from 'fs-extra';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import { stagepassPackageUrl } from './cdn-base.js';
|
|
3
|
+
import { defaultSnippetPins, stagepassPackageUrl } from './cdn-base.js';
|
|
4
|
+
|
|
5
|
+
const pins = defaultSnippetPins('stagepass');
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* Canonical CDN embed snippets recommended by Stagepass docs.
|
|
7
9
|
* Doctor checks these so generated / documented snippets never drift to @latest.
|
|
8
|
-
*
|
|
10
|
+
* Default host is the Stagepass CDN with the major alias `@2`.
|
|
9
11
|
*/
|
|
10
12
|
export const RECOMMENDED_CDN_SNIPPETS = Object.freeze([
|
|
11
|
-
stagepassPackageUrl('loader',
|
|
12
|
-
stagepassPackageUrl('modules',
|
|
13
|
-
stagepassPackageUrl('modules',
|
|
14
|
-
stagepassPackageUrl('modules',
|
|
15
|
-
stagepassPackageUrl('modules',
|
|
13
|
+
stagepassPackageUrl('loader', pins.loaderPin, 'loader.min.js'),
|
|
14
|
+
stagepassPackageUrl('modules', pins.modulesPin, 'inject.min.js'),
|
|
15
|
+
stagepassPackageUrl('modules', pins.modulesPin, 'cookies.min.js'),
|
|
16
|
+
stagepassPackageUrl('modules', pins.modulesPin, 'maintenance.min.js'),
|
|
17
|
+
stagepassPackageUrl('modules', pins.modulesPin, 'all.min.js'),
|
|
16
18
|
]);
|
|
17
19
|
|
|
18
20
|
/**
|
|
19
21
|
* Unpinned / legacy CDN pins for @stagepass/loader and @stagepass/modules:
|
|
20
22
|
* - `@latest`
|
|
21
|
-
* - bare major `@1` (not `@1.2.0` exact pins)
|
|
23
|
+
* - bare major `@1` (not `@2` or `@1.2.0` exact pins)
|
|
22
24
|
* - package URL with no `@version` at all
|
|
23
25
|
*
|
|
24
|
-
* Matches jsDelivr and unpkg
|
|
26
|
+
* Matches the Stagepass CDN, jsDelivr, and existing unpkg paths.
|
|
27
|
+
* The current major alias `@2` is the recommended default and is not flagged.
|
|
25
28
|
*/
|
|
26
29
|
export const UNPINNED_CDN_RE =
|
|
27
|
-
/(?:cdn\.jsdelivr\.net\/npm|unpkg\.com)\/@stagepass\/(?:loader|modules)(?:@latest|@1(?![0-9.])|(?!@))(?=[/"'?\s]|$)/gi;
|
|
30
|
+
/(?:cdn\.stagepass\.one\/(?:loader|modules)|(?:cdn\.jsdelivr\.net\/npm|unpkg\.com)\/@stagepass\/(?:loader|modules))(?:@latest|@1(?![0-9.])|(?!@))(?=[/"'?\s]|$)/gi;
|
|
28
31
|
|
|
29
32
|
/**
|
|
30
33
|
* Test whether a single URL/snippet string is an unpinned Stagepass CDN reference.
|
|
@@ -54,7 +57,7 @@ export function findUnpinnedCdnSnippets(snippets = RECOMMENDED_CDN_SNIPPETS) {
|
|
|
54
57
|
export function findUnpinnedCdnMatchesInText(content) {
|
|
55
58
|
const text = String(content || '');
|
|
56
59
|
const candidateRe =
|
|
57
|
-
/(?:https?:\/\/)?(?:cdn\.jsdelivr\.net\/npm|unpkg\.com)\/@stagepass\/(?:loader|modules)[^"'<\s]*/gi;
|
|
60
|
+
/(?:https?:\/\/)?(?:cdn\.stagepass\.one\/(?:loader|modules)|(?:cdn\.jsdelivr\.net\/npm|unpkg\.com)\/@stagepass\/(?:loader|modules))[^"'<\s]*/gi;
|
|
58
61
|
const matches = text.match(candidateRe);
|
|
59
62
|
if (!matches) return [];
|
|
60
63
|
const seen = new Set();
|
package/src/lib/doctor.js
CHANGED
|
@@ -567,7 +567,7 @@ export async function runDoctor(opts = {}) {
|
|
|
567
567
|
check(
|
|
568
568
|
'cdn',
|
|
569
569
|
'warn',
|
|
570
|
-
'Recommended CDN snippets include unpinned refs (@latest, @1, or bare package;
|
|
570
|
+
'Recommended CDN snippets include unpinned refs (@latest, @1, or bare package; use an exact version, or @2 on jsDelivr)',
|
|
571
571
|
unpinned.offenders.join(', ')
|
|
572
572
|
)
|
|
573
573
|
);
|
|
@@ -576,7 +576,7 @@ export async function runDoctor(opts = {}) {
|
|
|
576
576
|
check(
|
|
577
577
|
'cdn',
|
|
578
578
|
'ok',
|
|
579
|
-
'Recommended CDN snippets
|
|
579
|
+
'Recommended CDN snippets are pinned (exact version or major @2), not @latest/@1/bare'
|
|
580
580
|
)
|
|
581
581
|
);
|
|
582
582
|
}
|
|
@@ -599,7 +599,7 @@ export async function runDoctor(opts = {}) {
|
|
|
599
599
|
check(
|
|
600
600
|
'cdn.project',
|
|
601
601
|
'warn',
|
|
602
|
-
'Project files contain unpinned Stagepass CDN URLs (@latest, @1, or bare;
|
|
602
|
+
'Project files contain unpinned Stagepass CDN URLs (@latest, @1, or bare; use an exact version, or @2 on jsDelivr)',
|
|
603
603
|
detail
|
|
604
604
|
)
|
|
605
605
|
);
|
package/src/lib/origins.js
CHANGED
|
@@ -15,6 +15,8 @@ const HOSTNAME_LABEL_RE = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
|
|
|
15
15
|
const HOST_WHITESPACE_OR_CONTROL_RE = /[\s\x00-\x1f\x7f]/;
|
|
16
16
|
export const HOST_WHITESPACE_ERROR =
|
|
17
17
|
'Host must not contain whitespace or control characters.';
|
|
18
|
+
export const ORIGIN_PORT_ERROR =
|
|
19
|
+
'Origin allowlist is hostname-only (https, no port). Omit the port or use the default https port :443.';
|
|
18
20
|
|
|
19
21
|
/**
|
|
20
22
|
* Reject hosts / site inputs that contain whitespace or control characters.
|
|
@@ -53,14 +55,70 @@ export function isBroadWebflowWildcard(entry) {
|
|
|
53
55
|
return entry === '*.webflow.io' || entry === '*.webflow.com';
|
|
54
56
|
}
|
|
55
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Strip a pasted URL (or bare host with path/port) down to a hostname candidate.
|
|
60
|
+
* http(s) only; keeps a leading `*.` wildcard; strips path/query/fragment;
|
|
61
|
+
* strips default HTTPS port `:443` and rejects any other port.
|
|
62
|
+
*
|
|
63
|
+
* @param {string} input Lowercased raw string (no whitespace/controls).
|
|
64
|
+
* @returns {{ ok: true, host: string } | { ok: false, error: string }}
|
|
65
|
+
*/
|
|
66
|
+
function extractOriginHostname(input) {
|
|
67
|
+
let raw = input;
|
|
68
|
+
|
|
69
|
+
if (/^[a-z][a-z0-9+.-]*:\/\//.test(raw)) {
|
|
70
|
+
if (raw.startsWith('https://')) {
|
|
71
|
+
raw = raw.slice('https://'.length);
|
|
72
|
+
} else if (raw.startsWith('http://')) {
|
|
73
|
+
// Input convenience only; stored allowlist entries remain https origins.
|
|
74
|
+
raw = raw.slice('http://'.length);
|
|
75
|
+
} else {
|
|
76
|
+
return {
|
|
77
|
+
ok: false,
|
|
78
|
+
error: 'Origin must use http:// or https:// (or a bare hostname).',
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (raw.includes('@')) {
|
|
84
|
+
return { ok: false, error: 'Origin must not contain credentials.' };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Host only: drop path, query, and fragment (including a trailing slash).
|
|
88
|
+
const hostPart = raw.split(/[/?#]/, 1)[0];
|
|
89
|
+
if (!hostPart) {
|
|
90
|
+
return { ok: false, error: 'Origin entry is empty.' };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Ports: allow stripping the default HTTPS port; reject any other.
|
|
94
|
+
const lastColon = hostPart.lastIndexOf(':');
|
|
95
|
+
if (lastColon !== -1) {
|
|
96
|
+
// IPv6 is out of scope; a colon means an explicit port on a hostname.
|
|
97
|
+
const maybePort = hostPart.slice(lastColon + 1);
|
|
98
|
+
if (/^\d+$/.test(maybePort)) {
|
|
99
|
+
if (maybePort === '443') {
|
|
100
|
+
return { ok: true, host: hostPart.slice(0, lastColon) };
|
|
101
|
+
}
|
|
102
|
+
return { ok: false, error: ORIGIN_PORT_ERROR };
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
ok: false,
|
|
106
|
+
error: 'Origin must be a hostname (optional leading *.), no path or port.',
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return { ok: true, host: hostPart };
|
|
111
|
+
}
|
|
112
|
+
|
|
56
113
|
/**
|
|
57
114
|
* Validate a single live-domain / origin entry.
|
|
58
|
-
* Accepts: example.com | www.example.com | *.example.com |
|
|
115
|
+
* Accepts: example.com | www.example.com | *.example.com |
|
|
116
|
+
* https://example.com[/…] | http://example.com[/…] (http is input-only).
|
|
59
117
|
* Also accepts full Webflow staging hosts (my-project.webflow.io) and explicit
|
|
60
118
|
* wildcards (*.webflow.io) when passed by the user.
|
|
61
119
|
*
|
|
62
120
|
* @param {string} input
|
|
63
|
-
* @returns {{ ok: true, value: string } | { ok: false, error: string }}
|
|
121
|
+
* @returns {{ ok: true, value: string, normalised?: boolean } | { ok: false, error: string }}
|
|
64
122
|
*/
|
|
65
123
|
export function validateOriginEntry(input) {
|
|
66
124
|
if (typeof input !== 'string' || input === '') {
|
|
@@ -70,20 +128,10 @@ export function validateOriginEntry(input) {
|
|
|
70
128
|
const ws = rejectWhitespaceOrControls(input, 'Origin');
|
|
71
129
|
if (!ws.ok) return ws;
|
|
72
130
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
// Optional https:// only (http reserved for localhost defaults)
|
|
76
|
-
if (raw.startsWith('http://')) {
|
|
77
|
-
return { ok: false, error: 'Live origins must use https:// (or a bare hostname).' };
|
|
78
|
-
}
|
|
79
|
-
if (raw.startsWith('https://')) {
|
|
80
|
-
raw = raw.slice('https://'.length);
|
|
81
|
-
}
|
|
131
|
+
const extracted = extractOriginHostname(input.toLowerCase());
|
|
132
|
+
if (!extracted.ok) return extracted;
|
|
82
133
|
|
|
83
|
-
|
|
84
|
-
if (raw.includes('/') || raw.includes('?') || raw.includes('@') || raw.includes(':')) {
|
|
85
|
-
return { ok: false, error: 'Origin must be a hostname (optional leading *.), no path or port.' };
|
|
86
|
-
}
|
|
134
|
+
let raw = extracted.host;
|
|
87
135
|
|
|
88
136
|
let wildcard = false;
|
|
89
137
|
if (raw.startsWith('*.')) {
|
|
@@ -106,25 +154,30 @@ export function validateOriginEntry(input) {
|
|
|
106
154
|
}
|
|
107
155
|
|
|
108
156
|
const value = wildcard ? `*.${raw}` : raw;
|
|
109
|
-
|
|
157
|
+
const normalised = value !== input.toLowerCase();
|
|
158
|
+
return normalised ? { ok: true, value, normalised: true } : { ok: true, value };
|
|
110
159
|
}
|
|
111
160
|
|
|
112
161
|
/**
|
|
113
162
|
* @param {string[]} entries
|
|
114
|
-
* @returns {{ ok: true, origins: string[] } | { ok: false, error: string }}
|
|
163
|
+
* @returns {{ ok: true, origins: string[], normalised: string[] } | { ok: false, error: string }}
|
|
115
164
|
*/
|
|
116
165
|
export function validateOriginList(entries) {
|
|
117
166
|
const out = [];
|
|
167
|
+
const normalised = [];
|
|
118
168
|
const seen = new Set();
|
|
119
169
|
for (const entry of entries || []) {
|
|
120
170
|
const result = validateOriginEntry(entry);
|
|
121
171
|
if (!result.ok) return result;
|
|
172
|
+
if (result.normalised && !normalised.includes(result.value)) {
|
|
173
|
+
normalised.push(result.value);
|
|
174
|
+
}
|
|
122
175
|
if (!seen.has(result.value)) {
|
|
123
176
|
seen.add(result.value);
|
|
124
177
|
out.push(result.value);
|
|
125
178
|
}
|
|
126
179
|
}
|
|
127
|
-
return { ok: true, origins: out };
|
|
180
|
+
return { ok: true, origins: out, normalised };
|
|
128
181
|
}
|
|
129
182
|
|
|
130
183
|
/**
|
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* Sourced from packages/loader and packages/modules package.json at generate time.
|
|
6
6
|
* The published CLI ships this snapshot; it cannot read the monorepo at runtime.
|
|
7
7
|
*/
|
|
8
|
-
export const LOADER_VERSION = "2.5.
|
|
9
|
-
export const MODULES_VERSION = "2.2.
|
|
8
|
+
export const LOADER_VERSION = "2.5.2";
|
|
9
|
+
export const MODULES_VERSION = "2.2.3";
|
package/src/lib/project-sync.js
CHANGED
|
@@ -44,6 +44,7 @@ import {
|
|
|
44
44
|
import { loadProjects } from './projects.js';
|
|
45
45
|
import { validateOriginEntry, validateOriginList } from './origins.js';
|
|
46
46
|
import { describeDetection, normalizeSiteUrl, SITE_PORT_ERROR } from './site-detect.js';
|
|
47
|
+
import { normalizeCdnChoice } from './cdn-base.js';
|
|
47
48
|
|
|
48
49
|
/**
|
|
49
50
|
* Read and parse stagepass.json (null when missing or invalid).
|
|
@@ -110,6 +111,17 @@ export function phpFromStagepassConfig(data) {
|
|
|
110
111
|
return undefined;
|
|
111
112
|
}
|
|
112
113
|
|
|
114
|
+
/**
|
|
115
|
+
* CDN recorded by `stagepass new` (`stagepass` or `jsdelivr`).
|
|
116
|
+
* Absent, legacy, and unknown values use the Stagepass CDN.
|
|
117
|
+
* @param {Record<string, unknown> | null} data
|
|
118
|
+
* @returns {'stagepass' | 'jsdelivr'}
|
|
119
|
+
*/
|
|
120
|
+
export function cdnFromStagepassConfig(data) {
|
|
121
|
+
if (!data || typeof data !== 'object') return 'stagepass';
|
|
122
|
+
return normalizeCdnChoice(data.cdn) || 'stagepass';
|
|
123
|
+
}
|
|
124
|
+
|
|
113
125
|
/**
|
|
114
126
|
* Validate a staging/production hostname for `stagepass new` (origins.js rules).
|
|
115
127
|
* @param {string} input
|
|
@@ -734,6 +746,8 @@ async function isSymlink(abs, fse) {
|
|
|
734
746
|
* @param {boolean} [input.assumeYes] `--yes`: replace that file without asking
|
|
735
747
|
* @param {(question: string, defYes: boolean) => Promise<boolean>} [input.confirm]
|
|
736
748
|
* @param {boolean} [input.cursorRule] `--cursor-rule`: write the Cursor rule even without `.cursor/`
|
|
749
|
+
* @param {string} [input.cdn] `stagepass` or `jsdelivr`, same choice as the printed snippets
|
|
750
|
+
* @param {string} [input.loaderVersion] Sanitized exact loader pin shared with the printed snippets
|
|
737
751
|
* @param {typeof fs} [fse]
|
|
738
752
|
* @returns {Promise<{ writes: { file: string, content: string, action: string }[], notes: string[] }>}
|
|
739
753
|
*/
|
|
@@ -811,6 +825,8 @@ export async function planProjectSync(input, fse = fs) {
|
|
|
811
825
|
perModuleTypes,
|
|
812
826
|
}),
|
|
813
827
|
modulesDependency,
|
|
828
|
+
cdn: input.cdn,
|
|
829
|
+
loaderVersion: input.loaderVersion,
|
|
814
830
|
})
|
|
815
831
|
);
|
|
816
832
|
if (php && !phpBoilerplate) notes.push(PHP_LIB_MISSING_NOTE);
|
package/src/lib/registry.js
CHANGED
|
@@ -13,7 +13,7 @@ import { defaultExec } from './exec.js';
|
|
|
13
13
|
import { MODULE_IDS } from './project-modules.js';
|
|
14
14
|
import { SNIPPET_LOADER_VERSION } from './cdn-base.js';
|
|
15
15
|
|
|
16
|
-
/** Major range used for new
|
|
16
|
+
/** Major range used for new npm dependencies (matches the 2.x line used in CDN pins). */
|
|
17
17
|
export const PACKAGES_MAJOR_RANGE = '^2';
|
|
18
18
|
|
|
19
19
|
/** First @stagepass/modules release with per-module type entry points. */
|
package/src/lib/scaffold.js
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
renderStagepassAgentsFile,
|
|
11
11
|
} from './ai-guide.js';
|
|
12
12
|
import { typesForModules } from './project-modules.js';
|
|
13
|
-
import { SNIPPET_LOADER_VERSION } from './cdn-base.js';
|
|
13
|
+
import { SNIPPET_LOADER_VERSION, normalizeCdnChoice } from './cdn-base.js';
|
|
14
14
|
import { LOADER_VERSION, packagesRange } from './versions.js';
|
|
15
15
|
|
|
16
16
|
const __filename = fileURLToPath(import.meta.url);
|
|
@@ -100,6 +100,7 @@ export function scaffoldPhpTemplateMap(options = {}) {
|
|
|
100
100
|
* @property {boolean} install
|
|
101
101
|
* @property {boolean} dryRun
|
|
102
102
|
* @property {string} [loaderVersion] @stagepass/loader + modules version (snippets)
|
|
103
|
+
* @property {'stagepass' | 'jsdelivr'} [cdn] Webflow snippet CDN, stored in stagepass.json
|
|
103
104
|
* @property {string} [packagesRange] Override for package.json ranges (default ^<major>, e.g. ^2)
|
|
104
105
|
* @property {boolean} [perModuleTypes] false: use the umbrella `@stagepass/modules` types (modules < 2.2.0)
|
|
105
106
|
*/
|
|
@@ -176,6 +177,9 @@ export function buildStagepassExtraLines(options) {
|
|
|
176
177
|
}
|
|
177
178
|
// Always record php for new projects so link/doctor can tell intentional off from legacy.
|
|
178
179
|
lines.push(`\n "php": ${options.php === true ? 'true' : 'false'},`);
|
|
180
|
+
// Same default as snippet generation: missing or unknown values are the Stagepass CDN.
|
|
181
|
+
const cdn = normalizeCdnChoice(options.cdn) || 'stagepass';
|
|
182
|
+
lines.push(`\n "cdn": ${JSON.stringify(cdn)},`);
|
|
179
183
|
return lines.join('');
|
|
180
184
|
}
|
|
181
185
|
|
|
@@ -200,9 +204,11 @@ export async function planScaffoldFiles(options, deps = {}) {
|
|
|
200
204
|
const snippets = buildWebflowSnippets({
|
|
201
205
|
version,
|
|
202
206
|
moduleList: siteModules,
|
|
207
|
+
production: options.production,
|
|
203
208
|
gitRemote: options.git ? options.remote || '' : '',
|
|
204
209
|
gitBranch: options.git ? 'main' : '',
|
|
205
210
|
projectName: options.name,
|
|
211
|
+
cdn: options.cdn,
|
|
206
212
|
});
|
|
207
213
|
const types = typesForModules(siteModules, {
|
|
208
214
|
modulesDependency: options.modules === true,
|
|
@@ -293,6 +299,8 @@ export async function planScaffoldFiles(options, deps = {}) {
|
|
|
293
299
|
configFile,
|
|
294
300
|
types,
|
|
295
301
|
modulesDependency: options.modules === true,
|
|
302
|
+
cdn: options.cdn,
|
|
303
|
+
loaderVersion: version,
|
|
296
304
|
})
|
|
297
305
|
),
|
|
298
306
|
});
|
package/src/lib/site-detect.js
CHANGED
|
@@ -19,9 +19,12 @@ export { HOST_WHITESPACE_ERROR };
|
|
|
19
19
|
// Bounded attribute run keeps the scan linear on hostile input.
|
|
20
20
|
const SCRIPT_TAG_RE = /<script\b[^<>]{0,4096}>/gi;
|
|
21
21
|
const SRC_ATTR_RE = /\ssrc\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>]+))/i;
|
|
22
|
-
//
|
|
22
|
+
// jsDelivr / unpkg: /dist/<file>.js or package-root URLs (optional slash/query); root via package `main`.
|
|
23
23
|
const STAGEPASS_CDN_RE =
|
|
24
24
|
/^(?:https?:)?\/\/(cdn\.jsdelivr\.net\/npm|unpkg\.com)\/@stagepass\/(loader|modules)(?:@([0-9A-Za-z.^~_-]+))?(?:\/dist\/([a-z]+)(?:\.min)?\.js)?\/?(?:[?#].*)?$/i;
|
|
25
|
+
// Stagepass CDN: /loader@2.5.0/loader.min.js (no /dist/, no @scope). Short /loader@2.5.0 also matches.
|
|
26
|
+
const STAGEPASS_OWN_CDN_RE =
|
|
27
|
+
/^(?:https?:)?\/\/cdn\.stagepass\.one\/(loader|modules)(?:@([0-9A-Za-z.^~_-]+))?(?:\/([a-z]+)(?:\.min)?\.js)?\/?(?:[?#].*)?$/i;
|
|
25
28
|
// Self-hosted build filenames (need Stagepass path or data-* hint).
|
|
26
29
|
const STAGEPASS_FILE_RE = /(?:^|\/)(loader|inject|cookies|maintenance|all)(?:\.min)?\.js$/i;
|
|
27
30
|
// `…/stagepass/…` always; `…/@stagepass/…` only for relative src (blocks foreign-host spoofs).
|
|
@@ -148,6 +151,15 @@ export function parseStagepassScripts(html) {
|
|
|
148
151
|
if (!attr) continue;
|
|
149
152
|
const src = q(attr);
|
|
150
153
|
|
|
154
|
+
const ownMatch = STAGEPASS_OWN_CDN_RE.exec(src);
|
|
155
|
+
if (ownMatch) {
|
|
156
|
+
const pkg = ownMatch[1].toLowerCase();
|
|
157
|
+
const file = (ownMatch[3] || (pkg === 'modules' ? 'all' : 'loader')).toLowerCase();
|
|
158
|
+
if (pkg === 'loader' ? file === 'loader' : file !== 'loader') {
|
|
159
|
+
take(file, ownMatch[2] || 'latest', 'stagepass');
|
|
160
|
+
}
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
151
163
|
const cdnMatch = STAGEPASS_CDN_RE.exec(src);
|
|
152
164
|
if (cdnMatch) {
|
|
153
165
|
const pkg = cdnMatch[2].toLowerCase();
|
package/src/lib/snippets.js
CHANGED
|
@@ -3,17 +3,22 @@ import { promisify } from 'node:util';
|
|
|
3
3
|
import {
|
|
4
4
|
SNIPPET_LOADER_VERSION,
|
|
5
5
|
SNIPPET_MODULES_VERSION,
|
|
6
|
+
SNIPPET_MAJOR_PIN,
|
|
7
|
+
defaultSnippetPins,
|
|
8
|
+
normalizeCdnChoice,
|
|
6
9
|
stagepassPackageUrl,
|
|
7
10
|
} from './cdn-base.js';
|
|
11
|
+
import { validateOriginEntry } from './origins.js';
|
|
8
12
|
import { validateProjectName } from './project-name.js';
|
|
9
13
|
import { expandModules, normalizeModulesList } from './project-modules.js';
|
|
10
14
|
|
|
11
15
|
const execFileAsync = promisify(nodeExecFile);
|
|
12
16
|
|
|
13
|
-
/**
|
|
17
|
+
/** Owner/repo and similar plain tokens. Version pins use {@link SNIPPET_VERSION_RE}. */
|
|
14
18
|
const SNIPPET_TOKEN_BODY = '[0-9A-Za-z][0-9A-Za-z._+-]*';
|
|
15
|
-
const SNIPPET_VERSION_RE = new RegExp(`^[~^]?${SNIPPET_TOKEN_BODY}$`);
|
|
16
19
|
const SNIPPET_TOKEN_RE = new RegExp(`^${SNIPPET_TOKEN_BODY}$`);
|
|
20
|
+
/** Exact stable semver. Ranges, dist-tags, prerelease, and major aliases are rejected. */
|
|
21
|
+
const SNIPPET_VERSION_RE = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/;
|
|
17
22
|
|
|
18
23
|
const GITHUB_HTTPS_RE =
|
|
19
24
|
/^https?:\/\/(?:www\.)?github\.com(?::\d+)?\/([^/?#\s]+)\/([^/?#\s]+?)(?:\.git)?\/?(?:[?#].*)?$/i;
|
|
@@ -22,7 +27,8 @@ const GITHUB_SSH_URL_RE =
|
|
|
22
27
|
const GITHUB_SCP_RE = /^git@github\.com:([^/\s]+)\/([^/\s]+?)(?:\.git)?$/i;
|
|
23
28
|
|
|
24
29
|
/**
|
|
25
|
-
*
|
|
30
|
+
* Exact semver for CDN pins and data-stagepass-version (blocks HTML/attr injection).
|
|
31
|
+
* Accepts only `x.y.z`. Callers pass a registry-resolved release or `SNIPPET_LOADER_VERSION`.
|
|
26
32
|
* @param {unknown} version
|
|
27
33
|
* @returns {string}
|
|
28
34
|
*/
|
|
@@ -30,7 +36,7 @@ export function sanitizeSnippetVersion(version) {
|
|
|
30
36
|
const value = String(version == null ? '' : version).trim();
|
|
31
37
|
if (!SNIPPET_VERSION_RE.test(value)) {
|
|
32
38
|
throw new Error(
|
|
33
|
-
'Invalid version for Webflow snippets (use
|
|
39
|
+
'Invalid version for Webflow snippets (use an exact semver x.y.z).'
|
|
34
40
|
);
|
|
35
41
|
}
|
|
36
42
|
return value;
|
|
@@ -51,6 +57,20 @@ export function sanitizeSnippetToken(value) {
|
|
|
51
57
|
return token;
|
|
52
58
|
}
|
|
53
59
|
|
|
60
|
+
/**
|
|
61
|
+
* Concrete production hostname for footer asset URLs (no wildcard).
|
|
62
|
+
* Accepts a stored hostname or a pasted URL (same rules as #168).
|
|
63
|
+
* @param {unknown} production
|
|
64
|
+
* @returns {string | null}
|
|
65
|
+
*/
|
|
66
|
+
function concreteProductionHost(production) {
|
|
67
|
+
if (production == null || String(production) === '') return null;
|
|
68
|
+
// Config may have incidental spaces; CLI flags are validated raw elsewhere.
|
|
69
|
+
const check = validateOriginEntry(String(production).trim());
|
|
70
|
+
if (!check.ok || check.value.startsWith('*.')) return null;
|
|
71
|
+
return check.value;
|
|
72
|
+
}
|
|
73
|
+
|
|
54
74
|
/**
|
|
55
75
|
* @param {unknown} remote
|
|
56
76
|
* @returns {{ owner: string, repo: string } | null}
|
|
@@ -103,11 +123,26 @@ function safeBranch(branch) {
|
|
|
103
123
|
|
|
104
124
|
/**
|
|
105
125
|
* @param {object} [options]
|
|
126
|
+
* @param {unknown} [options.production]
|
|
106
127
|
* @param {unknown} [options.gitRemote]
|
|
107
128
|
* @param {unknown} [options.gitBranch]
|
|
108
129
|
* @param {unknown} [options.projectName]
|
|
109
130
|
*/
|
|
110
131
|
function describeProjectAssets(options = {}) {
|
|
132
|
+
const productionHost = concreteProductionHost(options.production);
|
|
133
|
+
if (productionHost) {
|
|
134
|
+
const base = `https://${productionHost}`;
|
|
135
|
+
const name = validateProjectName(options.projectName);
|
|
136
|
+
const segment = name.ok ? name.name : 'project';
|
|
137
|
+
return {
|
|
138
|
+
kind: 'production',
|
|
139
|
+
js: `${base}/js/main.js`,
|
|
140
|
+
css: `${base}/css/styles.css`,
|
|
141
|
+
exampleJs: `${base}/${segment}/main.a1b2c3d4.js`,
|
|
142
|
+
hint: 'After stagepass build, check dist/manifest.json for hashed file names.',
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
111
146
|
const parsed = parseGitHubRemote(options.gitRemote);
|
|
112
147
|
if (!parsed) {
|
|
113
148
|
const name = validateProjectName(options.projectName);
|
|
@@ -127,7 +162,7 @@ function describeProjectAssets(options = {}) {
|
|
|
127
162
|
js: `${base}/dist/main.js`,
|
|
128
163
|
css: `${base}/dist/styles.css`,
|
|
129
164
|
exampleJs: `${base}/dist/main.a1b2c3d4.js`,
|
|
130
|
-
hint: 'jsDelivr only serves public repos. A tag is a better production pin than a branch. After
|
|
165
|
+
hint: 'jsDelivr only serves public repos. A tag is a better production pin than a branch. After stagepass build, commit the dist folder, or check dist/manifest.json for hashed file names.',
|
|
131
166
|
};
|
|
132
167
|
}
|
|
133
168
|
|
|
@@ -136,16 +171,23 @@ function describeProjectAssets(options = {}) {
|
|
|
136
171
|
* @returns {string}
|
|
137
172
|
*/
|
|
138
173
|
function footerFor(assets) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
174
|
+
/** @type {string[]} */
|
|
175
|
+
let notes;
|
|
176
|
+
if (assets.kind === 'github') {
|
|
177
|
+
notes = [
|
|
178
|
+
'<!-- jsDelivr only serves public repos. A tag is a better production pin than a branch. -->',
|
|
179
|
+
'<!-- After `stagepass build`, commit the dist folder, or check dist/manifest.json for hashed file names. -->',
|
|
180
|
+
];
|
|
181
|
+
} else if (assets.kind === 'production') {
|
|
182
|
+
notes = [
|
|
183
|
+
'<!-- After `stagepass build`, check dist/manifest.json for hashed file names. -->',
|
|
184
|
+
];
|
|
185
|
+
} else {
|
|
186
|
+
notes = [
|
|
187
|
+
'<!-- Replace YOUR-PRODUCTION-URL with the host that serves your production assets. -->',
|
|
188
|
+
'<!-- After `stagepass build`, check dist/manifest.json for hashed file names. -->',
|
|
189
|
+
];
|
|
190
|
+
}
|
|
149
191
|
return [
|
|
150
192
|
...notes,
|
|
151
193
|
'<script',
|
|
@@ -163,19 +205,31 @@ function footerFor(assets) {
|
|
|
163
205
|
}
|
|
164
206
|
|
|
165
207
|
/**
|
|
166
|
-
* Build recommended Webflow Custom Code snippets
|
|
208
|
+
* Build recommended Webflow Custom Code snippets.
|
|
209
|
+
* Default host is the Stagepass CDN with the major alias `@2` and no
|
|
210
|
+
* `data-stagepass-version`. Pass `cdn: 'jsdelivr'` for the jsDelivr major pin.
|
|
211
|
+
* Pass `exact: true` (with `version`) for a documented Stagepass CDN exact pin.
|
|
167
212
|
*
|
|
168
213
|
* @param {object} options
|
|
169
|
-
* @param {string} options.version Exact
|
|
214
|
+
* @param {string} [options.version] Exact semver for jsDelivr `data-stagepass-version` or Stagepass exact pins
|
|
215
|
+
* @param {boolean} [options.exact] Stagepass CDN exact pin (full path + data-stagepass-version)
|
|
170
216
|
* @param {boolean} [options.modules] Legacy: true = inject + cookies tags
|
|
171
217
|
* @param {string[]} [options.moduleList] Declared modules (wins over `modules`)
|
|
218
|
+
* @param {string} [options.production] Concrete production host for footer asset URLs
|
|
172
219
|
* @param {string} [options.gitRemote] `origin` URL. GitHub https/ssh becomes a jsDelivr `/gh/` URL.
|
|
173
220
|
* @param {string} [options.gitBranch] Current branch. Missing or unsafe values use `main`.
|
|
174
221
|
* @param {string} [options.projectName] Used in the README placeholder example path.
|
|
175
|
-
* @
|
|
222
|
+
* @param {string} [options.cdn] `stagepass` (default) or `jsdelivr`
|
|
223
|
+
* @returns {{ head: string, footer: string, majorPin: string, exactPin: string, assetExampleUrl: string, assetHint: string, cdn: string }}
|
|
176
224
|
*/
|
|
177
|
-
export function buildWebflowSnippets(options) {
|
|
178
|
-
const
|
|
225
|
+
export function buildWebflowSnippets(options = {}) {
|
|
226
|
+
const exact = options.exact === true;
|
|
227
|
+
// Fail closed on an explicit unresolvable version (empty or invalid).
|
|
228
|
+
// Omitted version falls back to the bundled exact-pin literal (jsDelivr
|
|
229
|
+
// data-stagepass-version / documented exact pins only).
|
|
230
|
+
const version = sanitizeSnippetVersion(
|
|
231
|
+
options.version == null ? SNIPPET_LOADER_VERSION : options.version
|
|
232
|
+
);
|
|
179
233
|
/** @type {string[]} */
|
|
180
234
|
let moduleFiles = [];
|
|
181
235
|
if (Array.isArray(options.moduleList)) {
|
|
@@ -185,31 +239,47 @@ export function buildWebflowSnippets(options) {
|
|
|
185
239
|
} else if (options.modules === true) {
|
|
186
240
|
moduleFiles = ['inject', 'cookies'];
|
|
187
241
|
}
|
|
188
|
-
const
|
|
242
|
+
const cdnHost = normalizeCdnChoice(options.cdn) || 'stagepass';
|
|
243
|
+
const pins = defaultSnippetPins(cdnHost, {
|
|
244
|
+
loaderVersion: version,
|
|
245
|
+
exact: exact && cdnHost === 'stagepass',
|
|
246
|
+
});
|
|
247
|
+
const loaderPin = pins.loaderPin;
|
|
248
|
+
const modulesPin = pins.modulesPin;
|
|
189
249
|
const exactPin = `@${version}`;
|
|
190
250
|
const assets = describeProjectAssets(options);
|
|
251
|
+
const useVersionAttr = pins.cdn === 'jsdelivr' || (exact && pins.cdn === 'stagepass');
|
|
252
|
+
const loaderComment =
|
|
253
|
+
pins.cdn === 'jsdelivr'
|
|
254
|
+
? '<!-- Stagepass loader (jsDelivr major pin @2; optional exact pin shown in data-stagepass-version) -->'
|
|
255
|
+
: exact
|
|
256
|
+
? '<!-- Stagepass loader (Stagepass CDN, exact pin) -->'
|
|
257
|
+
: '<!-- Stagepass loader (Stagepass CDN, major pin @2) -->';
|
|
191
258
|
|
|
192
259
|
const loaderLines = [
|
|
193
|
-
|
|
260
|
+
loaderComment,
|
|
194
261
|
'<script',
|
|
195
|
-
` src="${stagepassPackageUrl('loader',
|
|
196
|
-
` data-stagepass-version="${version}"`,
|
|
197
|
-
'></script>',
|
|
262
|
+
` src="${stagepassPackageUrl('loader', loaderPin, 'loader.min.js', { cdn: pins.cdn })}"`,
|
|
198
263
|
];
|
|
264
|
+
if (useVersionAttr) {
|
|
265
|
+
loaderLines.push(` data-stagepass-version="${version}"`);
|
|
266
|
+
}
|
|
267
|
+
loaderLines.push('></script>');
|
|
199
268
|
|
|
200
269
|
for (const id of moduleFiles) {
|
|
201
270
|
loaderLines.push(
|
|
202
|
-
`<script src="${stagepassPackageUrl('modules',
|
|
271
|
+
`<script src="${stagepassPackageUrl('modules', modulesPin, `${id}.min.js`, { cdn: pins.cdn })}"></script>`
|
|
203
272
|
);
|
|
204
273
|
}
|
|
205
274
|
|
|
206
275
|
return {
|
|
207
276
|
head: loaderLines.join('\n'),
|
|
208
277
|
footer: footerFor(assets),
|
|
209
|
-
majorPin,
|
|
278
|
+
majorPin: SNIPPET_MAJOR_PIN,
|
|
210
279
|
exactPin,
|
|
211
280
|
assetExampleUrl: assets.exampleJs,
|
|
212
281
|
assetHint: assets.hint,
|
|
282
|
+
cdn: pins.cdn,
|
|
213
283
|
};
|
|
214
284
|
}
|
|
215
285
|
|
|
@@ -219,6 +289,8 @@ export function buildWebflowSnippets(options) {
|
|
|
219
289
|
* @param {object} [options]
|
|
220
290
|
* @param {string} [options.version]
|
|
221
291
|
* @param {string[]} [options.moduleList] Declared modules (`[]` when none)
|
|
292
|
+
* @param {string} [options.cdn]
|
|
293
|
+
* @param {boolean} [options.exact]
|
|
222
294
|
*/
|
|
223
295
|
export function buildOfficialHeadSnippets(options = {}) {
|
|
224
296
|
const raw = Array.isArray(options.moduleList) ? options.moduleList : [];
|
|
@@ -227,6 +299,8 @@ export function buildOfficialHeadSnippets(options = {}) {
|
|
|
227
299
|
return buildWebflowSnippets({
|
|
228
300
|
version: options.version,
|
|
229
301
|
moduleList: expandModules(parsed.modules),
|
|
302
|
+
cdn: options.cdn,
|
|
303
|
+
exact: options.exact,
|
|
230
304
|
});
|
|
231
305
|
}
|
|
232
306
|
|
|
@@ -269,6 +343,9 @@ async function gitText(cwd, args, exec) {
|
|
|
269
343
|
}
|
|
270
344
|
|
|
271
345
|
function logExactPin(log, snippets) {
|
|
346
|
+
// Only when the user opted into jsDelivr: optional exact-pin note.
|
|
347
|
+
// Default Stagepass CDN output does not advertise the jsDelivr alternative.
|
|
348
|
+
if (snippets?.cdn !== 'jsdelivr') return;
|
|
272
349
|
const loader = String(snippets?.exactPin || '').replace(/^@/, '') || SNIPPET_LOADER_VERSION;
|
|
273
350
|
log(
|
|
274
351
|
`\nOptional exact pin example (instead of @2): loader @${loader}, modules @${SNIPPET_MODULES_VERSION}.`
|