@stagepass/cli 2.5.0 → 2.6.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 +9 -8
- package/package.json +1 -1
- package/src/cli.js +1 -0
- package/src/commands/new.js +44 -1
- package/src/commands/upgrade.js +39 -24
- package/src/lib/ai-guide.js +31 -5
- package/src/lib/cdn-base.js +58 -6
- package/src/lib/cdn-snippets.js +12 -10
- package/src/lib/doctor.js +3 -3
- package/src/lib/package-versions.js +1 -1
- package/src/lib/project-sync.js +16 -0
- package/src/lib/registry.js +1 -1
- package/src/lib/scaffold.js +8 -1
- package/src/lib/site-detect.js +13 -1
- package/src/lib/snippets.js +40 -14
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
|
+
- CLI 2.6.0 (not yet published) generates Webflow snippets on `https://cdn.stagepass.one` with exact pins and full file paths. `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`, exact pins on `https://cdn.stagepass.one`). `stagepass upgrade` reads it back. CLI 2.6.0 (not yet published). |
|
|
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, exact pins, full file path, no `/dist/` segment; pass `--cdn jsdelivr` for the jsDelivr major pin `@2` 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 jsDelivr pin `@2`; the Stagepass CDN default uses an exact pin; npm installs the newest published 2.x). CLI 2.6.0 (not yet published). 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 always asks whether to enable PHP unless `--php` / `--no-php` was passed. Staging / production prompts, `--staging` detection, and `link` reading `origin` / `production` from `stagepass.json` are part of this release.
|
|
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 always asks for the snippet CDN (`stagepass` first, or `jsdelivr`) unless `--cdn` was passed, and whether to enable PHP unless `--php` / `--no-php` was passed. Staging / production prompts, `--staging` detection, and `link` reading `origin` / `production` from `stagepass.json` are part of this release.
|
|
131
132
|
|
|
132
133
|
### PHP
|
|
133
134
|
|
|
@@ -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.0/loader.min.js` and short aliases such as `/loader@2.5.0` (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. CLI 2.6.0 (not yet published) prints snippets on the Stagepass CDN with an exact pin, plus a jsDelivr alternative line. With `"cdn": "jsdelivr"` the snippets use the major pin `@2` and an optional exact pin note.
|
|
222
223
|
|
|
223
224
|
### Domain argument (`link` / `unlink`)
|
|
224
225
|
|
package/package.json
CHANGED
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/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';
|
|
@@ -181,6 +181,19 @@ export async function resolveNewOptions(nameArg, options = {}, deps = {}) {
|
|
|
181
181
|
siteModules = parsed.modules;
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
+
/** @type {string} */
|
|
185
|
+
let cdn = '';
|
|
186
|
+
if (options.cdn != null) {
|
|
187
|
+
const parsed = normalizeCdnChoice(options.cdn);
|
|
188
|
+
if (!parsed) {
|
|
189
|
+
return {
|
|
190
|
+
ok: false,
|
|
191
|
+
error: 'Invalid --cdn: use stagepass (default) or jsdelivr.',
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
cdn = parsed;
|
|
195
|
+
}
|
|
196
|
+
|
|
184
197
|
/** @type {string} */
|
|
185
198
|
let origin = '';
|
|
186
199
|
/** @type {string} */
|
|
@@ -328,6 +341,32 @@ export async function resolveNewOptions(nameArg, options = {}, deps = {}) {
|
|
|
328
341
|
else log(chalk.yellow(` ${parsed.error}`));
|
|
329
342
|
}
|
|
330
343
|
}
|
|
344
|
+
if (!cdn) {
|
|
345
|
+
// Bound retries: an invalid answer (for example "n" after y/N prompts)
|
|
346
|
+
// must not spin forever and grow memory.
|
|
347
|
+
const maxAttempts = 5;
|
|
348
|
+
let attempts = 0;
|
|
349
|
+
while (!cdn) {
|
|
350
|
+
const raw = await ask(
|
|
351
|
+
rl,
|
|
352
|
+
'CDN for Webflow snippets (stagepass | jsdelivr)',
|
|
353
|
+
'stagepass'
|
|
354
|
+
);
|
|
355
|
+
const parsed = normalizeCdnChoice(raw);
|
|
356
|
+
if (parsed) {
|
|
357
|
+
cdn = parsed;
|
|
358
|
+
break;
|
|
359
|
+
}
|
|
360
|
+
attempts += 1;
|
|
361
|
+
log(chalk.yellow(' Use stagepass (cdn.stagepass.one) or jsdelivr.'));
|
|
362
|
+
if (attempts >= maxAttempts) {
|
|
363
|
+
return {
|
|
364
|
+
ok: false,
|
|
365
|
+
error: 'Invalid --cdn: use stagepass (default) or jsdelivr.',
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
331
370
|
if (php === undefined) {
|
|
332
371
|
php = await askYesNo(rl, 'Enable PHP for this project?', false);
|
|
333
372
|
}
|
|
@@ -367,6 +406,8 @@ export async function resolveNewOptions(nameArg, options = {}, deps = {}) {
|
|
|
367
406
|
// The npm package (types) follows the declared list; keep the legacy default (included).
|
|
368
407
|
if (siteModules.length > 0) modules = true;
|
|
369
408
|
|
|
409
|
+
if (!cdn) cdn = 'stagepass';
|
|
410
|
+
|
|
370
411
|
// Non-interactive / --yes defaults
|
|
371
412
|
if (!name) {
|
|
372
413
|
return { ok: false, error: 'Project name is required (pass [name] or use a TTY).' };
|
|
@@ -441,6 +482,7 @@ export async function resolveNewOptions(nameArg, options = {}, deps = {}) {
|
|
|
441
482
|
dryRun: options.dryRun === true,
|
|
442
483
|
cursorRule: options.cursorRule === true,
|
|
443
484
|
loaderVersion: deps.packagesVersion || SNIPPET_LOADER_VERSION,
|
|
485
|
+
cdn,
|
|
444
486
|
},
|
|
445
487
|
};
|
|
446
488
|
}
|
|
@@ -854,6 +896,7 @@ export async function createNew(nameArg, options = {}, deps = {}) {
|
|
|
854
896
|
gitRemote: config.git ? config.remote || '' : '',
|
|
855
897
|
gitBranch: config.git ? 'main' : '',
|
|
856
898
|
projectName: config.name,
|
|
899
|
+
cdn: config.cdn,
|
|
857
900
|
});
|
|
858
901
|
printWebflowSnippets(snippets, log);
|
|
859
902
|
|
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,14 +528,6 @@ 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;
|
|
@@ -524,6 +538,7 @@ export async function upgrade(options = {}, deps = {}) {
|
|
|
524
538
|
gitRemote: gitRef && gitRef.gitRemote,
|
|
525
539
|
gitBranch: gitRef && gitRef.gitBranch,
|
|
526
540
|
projectName: pkg.name,
|
|
541
|
+
cdn,
|
|
527
542
|
});
|
|
528
543
|
} catch (err) {
|
|
529
544
|
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@${SNIPPET_MODULES_VERSION}/inject.min.js\` after \`loader.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@${SNIPPET_MODULES_VERSION}/cookies.min.js\` after \`loader.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@${SNIPPET_MODULES_VERSION}/maintenance.min.js\` after \`loader.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,24 @@ 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(
|
|
375
|
+
'loader',
|
|
376
|
+
`@${loaderVersion}`,
|
|
377
|
+
'loader.min.js',
|
|
378
|
+
{ cdn: 'stagepass' }
|
|
379
|
+
);
|
|
380
|
+
const jsdelivrLoaderUrl = stagepassPackageUrl(
|
|
381
|
+
'loader',
|
|
382
|
+
'@2',
|
|
383
|
+
'loader.min.js',
|
|
384
|
+
{ cdn: 'jsdelivr' }
|
|
385
|
+
);
|
|
386
|
+
const cdnLine =
|
|
387
|
+
cdnChoice === 'jsdelivr'
|
|
388
|
+
? `- **CDN:** This project uses jsDelivr (major pin \`@2\`), for example \`${jsdelivrLoaderUrl}\`. The Stagepass CDN exact pin is the alternative (\`${officialLoaderUrl}\`).`
|
|
389
|
+
: `- **CDN:** Stagepass CDN first, exact pin, full file path, no \`/dist/\` segment, for example \`${officialLoaderUrl}\`. jsDelivr is the alternative (\`${jsdelivrLoaderUrl}\`).`;
|
|
364
390
|
const parts = [
|
|
365
391
|
`# Stagepass (${name})`,
|
|
366
392
|
'',
|
|
@@ -386,14 +412,14 @@ export function buildStagepassGuide(ctx) {
|
|
|
386
412
|
'- **Session:** `localStorage` key `stagepass_domain`, JSON `{ domain, expires }` (default 12 h).',
|
|
387
413
|
'- **Modules:** separate script tags after `loader.min.js`. This file documents only the modules declared in `stagepass.json`.',
|
|
388
414
|
'- **Runtime:** call `sp` (same object as `window.stagepass`).',
|
|
389
|
-
|
|
415
|
+
cdnLine,
|
|
390
416
|
'',
|
|
391
417
|
'## Safe rules',
|
|
392
418
|
'',
|
|
393
419
|
'1. **No secrets in frontend code.** API keys, tokens, and passwords must never ship in JS or CSS served to the browser.',
|
|
394
420
|
'2. **No `innerHTML` with untrusted data.** Prefer `textContent`, `createElement`, or trusted, sanitized markup.',
|
|
395
421
|
'3. **No `eval` or string-built scripts** with user or CMS input.',
|
|
396
|
-
'4. **Pin versions** for production embeds (
|
|
422
|
+
'4. **Pin versions** for production embeds (exact pin on the Stagepass CDN, or jsDelivr major pin `@2`).',
|
|
397
423
|
'5. **Review before publishing.** Read the diff for asset tags, CORS origins, and Webflow Custom Code.',
|
|
398
424
|
'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
425
|
'7. **Do not commit secrets.** Keep `.env*` out of git.',
|
package/src/lib/cdn-base.js
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Official loader/modules CDN.
|
|
3
|
+
*
|
|
4
|
+
* Default host is https://cdn.stagepass.one: exact pins, full file path,
|
|
5
|
+
* no `/dist/` segment. jsDelivr remains an alternative (npm package paths,
|
|
6
|
+
* often a major pin, `/dist/` segment). Do not recommend unpkg.
|
|
7
|
+
*/
|
|
8
|
+
export const STAGEPASS_CDN_ORIGIN = 'https://cdn.stagepass.one';
|
|
9
|
+
export const STAGEPASS_JSDELIVR_CDN = 'https://cdn.jsdelivr.net/npm';
|
|
10
|
+
/** Default package CDN origin (Stagepass CDN). Prefer stagepassPackageUrl(). */
|
|
11
|
+
export const STAGEPASS_PACKAGE_CDN = STAGEPASS_CDN_ORIGIN;
|
|
3
12
|
|
|
4
13
|
/**
|
|
5
14
|
* Published npm versions for snippet exact pins (loader `latest`, modules `latest`).
|
|
@@ -8,13 +17,56 @@ export const STAGEPASS_PACKAGE_CDN = 'https://cdn.jsdelivr.net/npm';
|
|
|
8
17
|
*/
|
|
9
18
|
export const SNIPPET_LOADER_VERSION = '2.5.0';
|
|
10
19
|
export const SNIPPET_MODULES_VERSION = '2.2.2';
|
|
20
|
+
export const SNIPPET_MAJOR_PIN = '@2';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @param {unknown} raw
|
|
24
|
+
* @returns {'stagepass' | 'jsdelivr' | null}
|
|
25
|
+
*/
|
|
26
|
+
export function normalizeCdnChoice(raw) {
|
|
27
|
+
const v = String(raw == null ? '' : raw).trim().toLowerCase();
|
|
28
|
+
if (v === 'stagepass') return 'stagepass';
|
|
29
|
+
if (v === 'jsdelivr') return 'jsdelivr';
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Pins used in generated Webflow snippets for a CDN host.
|
|
35
|
+
* Stagepass CDN uses exact pins from the resolved loader version (the same
|
|
36
|
+
* value as `data-stagepass-version`). jsDelivr keeps the major pin `@2`.
|
|
37
|
+
* @param {unknown} [cdn]
|
|
38
|
+
* @param {{ loaderVersion?: string, modulesVersion?: string }} [options]
|
|
39
|
+
* @returns {{ cdn: 'stagepass' | 'jsdelivr', loaderPin: string, modulesPin: string }}
|
|
40
|
+
*/
|
|
41
|
+
export function defaultSnippetPins(cdn, options = {}) {
|
|
42
|
+
const host = normalizeCdnChoice(cdn) || 'stagepass';
|
|
43
|
+
if (host === 'jsdelivr') {
|
|
44
|
+
return {
|
|
45
|
+
cdn: host,
|
|
46
|
+
loaderPin: SNIPPET_MAJOR_PIN,
|
|
47
|
+
modulesPin: SNIPPET_MAJOR_PIN,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const loaderVersion = options.loaderVersion || SNIPPET_LOADER_VERSION;
|
|
51
|
+
const modulesVersion = options.modulesVersion || SNIPPET_MODULES_VERSION;
|
|
52
|
+
return {
|
|
53
|
+
cdn: host,
|
|
54
|
+
loaderPin: `@${loaderVersion}`,
|
|
55
|
+
modulesPin: `@${modulesVersion}`,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
11
58
|
|
|
12
59
|
/**
|
|
13
60
|
* @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 `
|
|
61
|
+
* @param {string} pin CDN pin including `@` (for example `@2` or `@2.5.0`)
|
|
62
|
+
* @param {string} file File under the host path (`loader.min.js`)
|
|
63
|
+
* @param {{ cdn?: string }} [options]
|
|
16
64
|
* @returns {string}
|
|
17
65
|
*/
|
|
18
|
-
export function stagepassPackageUrl(name, pin, file) {
|
|
19
|
-
|
|
66
|
+
export function stagepassPackageUrl(name, pin, file, options = {}) {
|
|
67
|
+
const cdn = normalizeCdnChoice(options.cdn) || 'stagepass';
|
|
68
|
+
if (cdn === 'jsdelivr') {
|
|
69
|
+
return `${STAGEPASS_JSDELIVR_CDN}/@stagepass/${name}${pin}/dist/${file}`;
|
|
70
|
+
}
|
|
71
|
+
return `${STAGEPASS_CDN_ORIGIN}/${name}${pin}/${file}`;
|
|
20
72
|
}
|
package/src/lib/cdn-snippets.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
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 exact pins.
|
|
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
|
/**
|
|
@@ -21,10 +23,10 @@ export const RECOMMENDED_CDN_SNIPPETS = Object.freeze([
|
|
|
21
23
|
* - bare major `@1` (not `@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.
|
|
25
27
|
*/
|
|
26
28
|
export const UNPINNED_CDN_RE =
|
|
27
|
-
/(?:cdn\.jsdelivr\.net\/npm|unpkg\.com)\/@stagepass\/(?:loader|modules)(?:@latest|@1(?![0-9.])|(?!@))(?=[/"'?\s]|$)/gi;
|
|
29
|
+
/(?:cdn\.stagepass\.one\/(?:loader|modules)|(?:cdn\.jsdelivr\.net\/npm|unpkg\.com)\/@stagepass\/(?:loader|modules))(?:@latest|@1(?![0-9.])|(?!@))(?=[/"'?\s]|$)/gi;
|
|
28
30
|
|
|
29
31
|
/**
|
|
30
32
|
* Test whether a single URL/snippet string is an unpinned Stagepass CDN reference.
|
|
@@ -54,7 +56,7 @@ export function findUnpinnedCdnSnippets(snippets = RECOMMENDED_CDN_SNIPPETS) {
|
|
|
54
56
|
export function findUnpinnedCdnMatchesInText(content) {
|
|
55
57
|
const text = String(content || '');
|
|
56
58
|
const candidateRe =
|
|
57
|
-
/(?:https?:\/\/)?(?:cdn\.jsdelivr\.net\/npm|unpkg\.com)\/@stagepass\/(?:loader|modules)[^"'<\s]*/gi;
|
|
59
|
+
/(?:https?:\/\/)?(?:cdn\.stagepass\.one\/(?:loader|modules)|(?:cdn\.jsdelivr\.net\/npm|unpkg\.com)\/@stagepass\/(?:loader|modules))[^"'<\s]*/gi;
|
|
58
60
|
const matches = text.match(candidateRe);
|
|
59
61
|
if (!matches) return [];
|
|
60
62
|
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
|
);
|
|
@@ -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.
|
|
8
|
+
export const LOADER_VERSION = "2.5.1";
|
|
9
9
|
export const MODULES_VERSION = "2.2.2";
|
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
|
|
|
@@ -203,6 +207,7 @@ export async function planScaffoldFiles(options, deps = {}) {
|
|
|
203
207
|
gitRemote: options.git ? options.remote || '' : '',
|
|
204
208
|
gitBranch: options.git ? 'main' : '',
|
|
205
209
|
projectName: options.name,
|
|
210
|
+
cdn: options.cdn,
|
|
206
211
|
});
|
|
207
212
|
const types = typesForModules(siteModules, {
|
|
208
213
|
modulesDependency: options.modules === true,
|
|
@@ -293,6 +298,8 @@ export async function planScaffoldFiles(options, deps = {}) {
|
|
|
293
298
|
configFile,
|
|
294
299
|
types,
|
|
295
300
|
modulesDependency: options.modules === true,
|
|
301
|
+
cdn: options.cdn,
|
|
302
|
+
loaderVersion: version,
|
|
296
303
|
})
|
|
297
304
|
),
|
|
298
305
|
});
|
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,6 +3,7 @@ import { promisify } from 'node:util';
|
|
|
3
3
|
import {
|
|
4
4
|
SNIPPET_LOADER_VERSION,
|
|
5
5
|
SNIPPET_MODULES_VERSION,
|
|
6
|
+
defaultSnippetPins,
|
|
6
7
|
stagepassPackageUrl,
|
|
7
8
|
} from './cdn-base.js';
|
|
8
9
|
import { validateProjectName } from './project-name.js';
|
|
@@ -10,10 +11,11 @@ import { expandModules, normalizeModulesList } from './project-modules.js';
|
|
|
10
11
|
|
|
11
12
|
const execFileAsync = promisify(nodeExecFile);
|
|
12
13
|
|
|
13
|
-
/**
|
|
14
|
+
/** Owner/repo and similar plain tokens. Version pins use {@link SNIPPET_VERSION_RE}. */
|
|
14
15
|
const SNIPPET_TOKEN_BODY = '[0-9A-Za-z][0-9A-Za-z._+-]*';
|
|
15
|
-
const SNIPPET_VERSION_RE = new RegExp(`^[~^]?${SNIPPET_TOKEN_BODY}$`);
|
|
16
16
|
const SNIPPET_TOKEN_RE = new RegExp(`^${SNIPPET_TOKEN_BODY}$`);
|
|
17
|
+
/** Exact stable semver. Ranges, dist-tags, prerelease, and major aliases are rejected. */
|
|
18
|
+
const SNIPPET_VERSION_RE = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/;
|
|
17
19
|
|
|
18
20
|
const GITHUB_HTTPS_RE =
|
|
19
21
|
/^https?:\/\/(?:www\.)?github\.com(?::\d+)?\/([^/?#\s]+)\/([^/?#\s]+?)(?:\.git)?\/?(?:[?#].*)?$/i;
|
|
@@ -22,7 +24,8 @@ const GITHUB_SSH_URL_RE =
|
|
|
22
24
|
const GITHUB_SCP_RE = /^git@github\.com:([^/\s]+)\/([^/\s]+?)(?:\.git)?$/i;
|
|
23
25
|
|
|
24
26
|
/**
|
|
25
|
-
*
|
|
27
|
+
* Exact semver for CDN pins and data-stagepass-version (blocks HTML/attr injection).
|
|
28
|
+
* Accepts only `x.y.z`. Callers pass a registry-resolved release or `SNIPPET_LOADER_VERSION`.
|
|
26
29
|
* @param {unknown} version
|
|
27
30
|
* @returns {string}
|
|
28
31
|
*/
|
|
@@ -30,7 +33,7 @@ export function sanitizeSnippetVersion(version) {
|
|
|
30
33
|
const value = String(version == null ? '' : version).trim();
|
|
31
34
|
if (!SNIPPET_VERSION_RE.test(value)) {
|
|
32
35
|
throw new Error(
|
|
33
|
-
'Invalid version for Webflow snippets (use
|
|
36
|
+
'Invalid version for Webflow snippets (use an exact semver x.y.z).'
|
|
34
37
|
);
|
|
35
38
|
}
|
|
36
39
|
return value;
|
|
@@ -163,19 +166,27 @@ function footerFor(assets) {
|
|
|
163
166
|
}
|
|
164
167
|
|
|
165
168
|
/**
|
|
166
|
-
* Build recommended Webflow Custom Code snippets
|
|
169
|
+
* Build recommended Webflow Custom Code snippets.
|
|
170
|
+
* Default host is the Stagepass CDN with exact pins. Pass `cdn: 'jsdelivr'`
|
|
171
|
+
* for the jsDelivr major pin `@2` alternative.
|
|
167
172
|
*
|
|
168
173
|
* @param {object} options
|
|
169
|
-
* @param {string} options.version Exact package version for data-stagepass-version
|
|
174
|
+
* @param {string} options.version Exact package version for the Stagepass CDN URL pin and data-stagepass-version
|
|
170
175
|
* @param {boolean} [options.modules] Legacy: true = inject + cookies tags
|
|
171
176
|
* @param {string[]} [options.moduleList] Declared modules (wins over `modules`)
|
|
172
177
|
* @param {string} [options.gitRemote] `origin` URL. GitHub https/ssh becomes a jsDelivr `/gh/` URL.
|
|
173
178
|
* @param {string} [options.gitBranch] Current branch. Missing or unsafe values use `main`.
|
|
174
179
|
* @param {string} [options.projectName] Used in the README placeholder example path.
|
|
175
|
-
* @
|
|
180
|
+
* @param {string} [options.cdn] `stagepass` (default) or `jsdelivr`
|
|
181
|
+
* @returns {{ head: string, footer: string, majorPin: string, exactPin: string, assetExampleUrl: string, assetHint: string, cdn: string }}
|
|
176
182
|
*/
|
|
177
183
|
export function buildWebflowSnippets(options) {
|
|
178
|
-
|
|
184
|
+
// Fail closed on an explicit unresolvable version (empty or invalid).
|
|
185
|
+
// Omitted version falls back to the bundled exact pin, used for both the
|
|
186
|
+
// Stagepass CDN URL and data-stagepass-version (single source of truth).
|
|
187
|
+
const version = sanitizeSnippetVersion(
|
|
188
|
+
options.version == null ? SNIPPET_LOADER_VERSION : options.version
|
|
189
|
+
);
|
|
179
190
|
/** @type {string[]} */
|
|
180
191
|
let moduleFiles = [];
|
|
181
192
|
if (Array.isArray(options.moduleList)) {
|
|
@@ -185,31 +196,38 @@ export function buildWebflowSnippets(options) {
|
|
|
185
196
|
} else if (options.modules === true) {
|
|
186
197
|
moduleFiles = ['inject', 'cookies'];
|
|
187
198
|
}
|
|
188
|
-
const
|
|
199
|
+
const pins = defaultSnippetPins(options.cdn, { loaderVersion: version });
|
|
200
|
+
const loaderPin = pins.loaderPin;
|
|
201
|
+
const modulesPin = pins.modulesPin;
|
|
189
202
|
const exactPin = `@${version}`;
|
|
190
203
|
const assets = describeProjectAssets(options);
|
|
204
|
+
const loaderComment =
|
|
205
|
+
pins.cdn === 'jsdelivr'
|
|
206
|
+
? '<!-- Stagepass loader (jsDelivr major pin @2; optional exact pin shown in data-stagepass-version) -->'
|
|
207
|
+
: '<!-- Stagepass loader (Stagepass CDN, exact pin) -->';
|
|
191
208
|
|
|
192
209
|
const loaderLines = [
|
|
193
|
-
|
|
210
|
+
loaderComment,
|
|
194
211
|
'<script',
|
|
195
|
-
` src="${stagepassPackageUrl('loader',
|
|
212
|
+
` src="${stagepassPackageUrl('loader', loaderPin, 'loader.min.js', { cdn: pins.cdn })}"`,
|
|
196
213
|
` data-stagepass-version="${version}"`,
|
|
197
214
|
'></script>',
|
|
198
215
|
];
|
|
199
216
|
|
|
200
217
|
for (const id of moduleFiles) {
|
|
201
218
|
loaderLines.push(
|
|
202
|
-
`<script src="${stagepassPackageUrl('modules',
|
|
219
|
+
`<script src="${stagepassPackageUrl('modules', modulesPin, `${id}.min.js`, { cdn: pins.cdn })}"></script>`
|
|
203
220
|
);
|
|
204
221
|
}
|
|
205
222
|
|
|
206
223
|
return {
|
|
207
224
|
head: loaderLines.join('\n'),
|
|
208
225
|
footer: footerFor(assets),
|
|
209
|
-
majorPin,
|
|
226
|
+
majorPin: loaderPin,
|
|
210
227
|
exactPin,
|
|
211
228
|
assetExampleUrl: assets.exampleJs,
|
|
212
229
|
assetHint: assets.hint,
|
|
230
|
+
cdn: pins.cdn,
|
|
213
231
|
};
|
|
214
232
|
}
|
|
215
233
|
|
|
@@ -227,6 +245,7 @@ export function buildOfficialHeadSnippets(options = {}) {
|
|
|
227
245
|
return buildWebflowSnippets({
|
|
228
246
|
version: options.version,
|
|
229
247
|
moduleList: expandModules(parsed.modules),
|
|
248
|
+
cdn: options.cdn,
|
|
230
249
|
});
|
|
231
250
|
}
|
|
232
251
|
|
|
@@ -269,9 +288,16 @@ async function gitText(cwd, args, exec) {
|
|
|
269
288
|
}
|
|
270
289
|
|
|
271
290
|
function logExactPin(log, snippets) {
|
|
291
|
+
// exactPin is `@` plus the sanitized version already used in the head snippet.
|
|
272
292
|
const loader = String(snippets?.exactPin || '').replace(/^@/, '') || SNIPPET_LOADER_VERSION;
|
|
293
|
+
if (snippets?.cdn === 'jsdelivr') {
|
|
294
|
+
log(
|
|
295
|
+
`\nOptional exact pin example (instead of @2): loader @${loader}, modules @${SNIPPET_MODULES_VERSION}.`
|
|
296
|
+
);
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
273
299
|
log(
|
|
274
|
-
`\
|
|
300
|
+
`\njsDelivr alternative (major pin @2): <script src="https://cdn.jsdelivr.net/npm/@stagepass/loader@2/dist/loader.min.js" data-stagepass-version="${loader}"></script>`
|
|
275
301
|
);
|
|
276
302
|
}
|
|
277
303
|
|