@stagepass/loader 1.2.0 → 2.1.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/LICENSE +21 -0
- package/README.md +95 -24
- package/dist/loader.js +636 -232
- package/dist/loader.min.js +2 -2
- package/global.d.ts +124 -0
- package/package.json +11 -7
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Robert Herz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -7,48 +7,119 @@ The loader reads Stagepass session state and swaps tagged production assets with
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
npm install @stagepass/loader
|
|
10
|
+
npm install @stagepass/loader@2
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
## CDN Usage
|
|
14
14
|
|
|
15
|
+
Prefer the major pin `@2` in production on jsDelivr. Stagepass follows strict semver: no breaking changes within v2; breaking changes only in a new major (v3). Exact pins (e.g. `@2.1.0`) are optional for maximum control. jsDelivr may cache `@2` for a while; purge with `https://purge.jsdelivr.net/npm/@stagepass/loader@2/dist/loader.min.js`. See the root README [Version pinning](../../README.md#-version-pinning) section.
|
|
16
|
+
|
|
15
17
|
```html
|
|
16
|
-
<script
|
|
18
|
+
<script
|
|
19
|
+
src="https://cdn.jsdelivr.net/npm/@stagepass/loader@2/dist/loader.min.js"
|
|
20
|
+
data-stagepass-version="2.1.0"
|
|
21
|
+
></script>
|
|
17
22
|
```
|
|
18
23
|
|
|
24
|
+
unpkg serves the same paths if you need an alternative CDN.
|
|
25
|
+
|
|
26
|
+
See [MIGRATION.md](../../MIGRATION.md) for breaking changes from 1.x.
|
|
27
|
+
|
|
19
28
|
## What it does
|
|
20
29
|
|
|
21
|
-
- Processes `script[data-stagepass]` and `link[rel="stylesheet"][data-stagepass]`.
|
|
22
|
-
- Uses `data-src` / `data-href` as
|
|
23
|
-
- Uses `data-stagepass-path` as optional local path
|
|
24
|
-
-
|
|
25
|
-
-
|
|
30
|
+
- Processes `script[data-stagepass]:not([data-stagepass-processed])` and `link[rel="stylesheet"][data-stagepass]:not([data-stagepass-processed])`.
|
|
31
|
+
- Uses `data-src` (scripts) / `data-href` (stylesheets) as the production URL.
|
|
32
|
+
- Uses `data-stagepass-path` as an optional local path; if omitted while swapping, the filename is taken from the production URL.
|
|
33
|
+
- Inserts the new element before the original, then removes the original (`data-stagepass-processed` prevents double work).
|
|
34
|
+
- Local session: cache-bust with a single `?_cb=<timestamp>` per page load.
|
|
35
|
+
- Production: version bust with `data-stagepass-version` (loader tag) and/or `data-stagepass-v` (per asset) → `?v=<version>` (URL-encoded; existing query/hash preserved).
|
|
36
|
+
- `data-stagepass-cachebust="true"` is legacy and **does not** timestamp every production view in v2.
|
|
37
|
+
- Session expiry (default **12 h**): `data-stagepass-session-hours` on the loader tag.
|
|
38
|
+
- Optional legacy global console mute: `data-stagepass-mute-console="true"` (production, no session only).
|
|
39
|
+
- Dynamically created scripts use `async=false` unless the original had `async`; `defer` is added when neither async nor defer was set (keeps classic order).
|
|
40
|
+
- Chrome Local Network Access: best-effort permission query; badge/console hint when state is `prompt` or `denied`.
|
|
41
|
+
|
|
42
|
+
## Loader tag attributes
|
|
43
|
+
|
|
44
|
+
| Attribute | Effect |
|
|
45
|
+
| :--- | :--- |
|
|
46
|
+
| `data-stagepass-version` | Production default `?v=<version>` for swapped/tagged assets without a per-asset override. |
|
|
47
|
+
| `data-stagepass-session-hours` | Session lifetime in hours (positive number; default `12`). |
|
|
48
|
+
| `data-stagepass-mute-console="true"` | Opt-in legacy mute of `console.log/warn/error/info/debug` in production when no session. |
|
|
49
|
+
| `data-stagepass-staging-hosts` | Comma-separated hostnames treated as staging (in addition to `*.webflow.io`). |
|
|
50
|
+
| `data-stagepass-alias` | Optional custom global name (valid JS identifier). Assigned only when that global is free. |
|
|
51
|
+
|
|
52
|
+
## Asset attributes
|
|
53
|
+
|
|
54
|
+
| Attribute | Effect |
|
|
55
|
+
| :--- | :--- |
|
|
56
|
+
| `data-stagepass` | Marks the element for processing (any value). |
|
|
57
|
+
| `data-src` / `data-href` | Production URL (required for processing). |
|
|
58
|
+
| `data-stagepass-path` | Local path under the linked project root (optional). |
|
|
59
|
+
| `data-stagepass-v` | Per-asset production `?v=<version>` (overrides loader `data-stagepass-version`). |
|
|
60
|
+
| `data-stagepass-cachebust` | Legacy; ignored for production timestamps in v2. |
|
|
61
|
+
| `data-stagepass-processed` | Internal; set after processing. |
|
|
26
62
|
|
|
27
|
-
##
|
|
63
|
+
## URL Modes
|
|
28
64
|
|
|
29
|
-
|
|
65
|
+
- `?stagepass=my-project.sp`: activate local swapping (expires; default 12 h).
|
|
66
|
+
- `?stagepass=debug`: logging only (no asset swap).
|
|
67
|
+
- `?stagepass=off` / `0` / `false`: clear the session.
|
|
30
68
|
|
|
31
|
-
|
|
32
|
-
- `sp.vars.env`
|
|
33
|
-
- `sp.vars.domain`
|
|
34
|
-
- `sp.vars.timestamp`
|
|
35
|
-
- `sp.vars.version`
|
|
36
|
-
- `sp.vars.client.*` (theme/browser/os/device/viewport/locale/capabilities)
|
|
37
|
-
- `sp.resolveLocalUrl(relativePath)`
|
|
38
|
-
- `sp.log(...)`, `sp.warn(...)`, `sp.error(...)`
|
|
69
|
+
Allowed session values: `*.sp`, `localhost`, `localhost:<port>`, `debug`. Invalid values are rejected/cleared.
|
|
39
70
|
|
|
40
|
-
|
|
71
|
+
After handling, `?stagepass=` is removed with `history.replaceState` (other query params and the hash are kept).
|
|
41
72
|
|
|
42
|
-
|
|
73
|
+
Storage key: `localStorage.stagepass_domain` → JSON `{ "domain": "…", "expires": <ms> }`. Legacy plain-string values are cleared.
|
|
74
|
+
|
|
75
|
+
## Badge
|
|
76
|
+
|
|
77
|
+
Shown only while a session is active (including debug). Click clears the session and reloads.
|
|
78
|
+
|
|
79
|
+
| State | Text |
|
|
80
|
+
| :--- | :--- |
|
|
81
|
+
| Active swap | `STAGEPASS ACTIVE` |
|
|
82
|
+
| Debug | `STAGEPASS DEBUG` |
|
|
83
|
+
| Active + LNA prompt/denied | `STAGEPASS · ALLOW LOCAL NETWORK` |
|
|
84
|
+
| Debug + LNA prompt/denied | `STAGEPASS DEBUG · LNA` |
|
|
85
|
+
|
|
86
|
+
## Runtime API
|
|
87
|
+
|
|
88
|
+
Preferred global is `sp` (aliases: `stagepass`, `window.stagepass`). Optional custom alias via `data-stagepass-alias` when free. Types ship in `global.d.ts`.
|
|
89
|
+
|
|
90
|
+
```js
|
|
91
|
+
sp.vars.isLocal // boolean: session swap active or page on localhost
|
|
92
|
+
sp.vars.env // 'local' | 'staging' | 'production' (localhost counts as local)
|
|
93
|
+
sp.vars.domain // active .sp domain, or page hostname when no swap
|
|
94
|
+
sp.vars.timestamp // session start ms while swapping; otherwise 0
|
|
95
|
+
sp.vars.version // package version (build-time)
|
|
96
|
+
sp.vars.client // theme / browser / os / device / viewport / locale / capabilities
|
|
97
|
+
|
|
98
|
+
// Flat helpers (additive)
|
|
99
|
+
sp.env() // 'local' | 'staging' | 'production'
|
|
100
|
+
// local = active swap to a .sp domain
|
|
101
|
+
// staging = *.webflow.io or data-stagepass-staging-hosts
|
|
102
|
+
sp.is('staging')
|
|
103
|
+
sp.can('localStorage') // also: sessionStorage, cookies, serviceWorker
|
|
104
|
+
sp.client('theme') // or sp.client() for the whole object
|
|
105
|
+
const off = sp.on('theme', (t) => { /* prefers-color-scheme change */ })
|
|
106
|
+
off()
|
|
107
|
+
sp.use('my-module', '2.1.0', (api) => { /* register */ })
|
|
108
|
+
|
|
109
|
+
sp.resolveLocalUrl('js/app.js') // local HTTPS URL while swapping; '' otherwise
|
|
110
|
+
sp.log('...') / sp.log('warn', '...') / sp.log('error', '...')
|
|
111
|
+
sp.warn('...')
|
|
112
|
+
sp.error('...')
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Logging helpers only print while a Stagepass session is active. Deprecated globals `splog` / `spwarn` / `sperror` were removed in v2.
|
|
43
116
|
|
|
44
|
-
|
|
45
|
-
- `?stagepass=debug` - logging only.
|
|
46
|
-
- `?stagepass=off` - deactivate session.
|
|
117
|
+
With an active session (or debug), the loader warns when two tagged assets resolve to the same local filename without `data-stagepass-path`.
|
|
47
118
|
|
|
48
119
|
## Related Packages
|
|
49
120
|
|
|
50
|
-
- `@stagepass/cli
|
|
51
|
-
- `@stagepass/modules
|
|
121
|
+
- `@stagepass/cli`: creates and manages `.sp` infrastructure.
|
|
122
|
+
- `@stagepass/modules`: optional modules that extend the loader (`inject`, `cookies`, `maintenance`).
|
|
52
123
|
|
|
53
124
|
## Repository
|
|
54
125
|
|