workers-start 0.6.1 → 0.7.1
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/CHANGELOG.md +11 -0
- package/README.md +41 -1
- package/dist/cache.d.ts +41 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +64 -0
- package/dist/cache.js.map +1 -0
- package/dist/check-bundle.d.ts +0 -14
- package/dist/check-bundle.d.ts.map +1 -1
- package/dist/check-bundle.js +5 -5
- package/dist/check-bundle.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/scripts.d.ts +10 -0
- package/dist/scripts.d.ts.map +1 -1
- package/dist/scripts.js +16 -0
- package/dist/scripts.js.map +1 -1
- package/package.json +14 -12
- package/src/cache.ts +95 -0
- package/src/check-bundle.ts +5 -7
- package/src/index.ts +8 -0
- package/src/scripts.ts +24 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.7.1 (2026-11-20)
|
|
4
|
+
|
|
5
|
+
- Package metadata (`repository`, `homepage`, `bugs`) points at [ryanio/workers-kit](https://github.com/ryanio/workers-kit), where the package now lives. The first release published from there.
|
|
6
|
+
|
|
7
|
+
## 0.7.0 (2026-11-20)
|
|
8
|
+
|
|
9
|
+
- `workers-start/cache`: `withEdgeCache(request, render, { version })` keeps rendered pages in the Workers Cache API by their `s-maxage`, with `sharedMaxAge` and `withoutBrowserMaxAge`.
|
|
10
|
+
- `workers-start/scripts`: `gaEvent(name, params)` sends an analytics event through `gtag` or a Tag Manager `dataLayer`, and does nothing where neither loaded.
|
|
11
|
+
- `workers-start/check-bundle` no longer exports its internal helpers (`MIN_SECRET_LENGTH`, `encodings`, `localEnvPairs`, `listFiles`, `readBuilt`). They were never documented and no consumer imported them; the bin and `DEFAULT_SKIP`/`DEFAULT_PUBLIC_PREFIXES` are unchanged.
|
|
12
|
+
- README: an index of every entry point.
|
|
13
|
+
|
|
3
14
|
## 0.6.1 (2026-11-20)
|
|
4
15
|
|
|
5
16
|
- `inlineJson` also escapes `>` and `&`, so every inline script the package builds escapes the same five characters. The output still parses to the same value.
|
package/README.md
CHANGED
|
@@ -4,6 +4,21 @@ The parts every TanStack Start app on Cloudflare Workers ends up writing by hand
|
|
|
4
4
|
|
|
5
5
|
It has no runtime dependencies. Each piece is its own entry point, so an app takes only what it uses.
|
|
6
6
|
|
|
7
|
+
## What is in it
|
|
8
|
+
|
|
9
|
+
Check this list before writing a helper in an app. Anything generic to TanStack Start on Workers that is missing belongs here, with a test, rather than in one app.
|
|
10
|
+
|
|
11
|
+
| Entry point | Exports | For |
|
|
12
|
+
| ---------------------------- | ----------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ |
|
|
13
|
+
| `workers-start/entry` | `createEntry`, `withHeaders`, `wantsMarkdown`, `acceptsHtml` | The Worker entry: Markdown for agents, Accept fixes, 405s, headers on every response |
|
|
14
|
+
| `workers-start/head` | `createPageHead`, `jsonLdScript` | Per-route head tags and escaped JSON-LD |
|
|
15
|
+
| `workers-start/scripts` | `themeScript`, `analyticsScript`, `tagManagerScript`, `gaEvent`, `inlineJson` | Inline bootstraps, analytics events, JSON safe inside a script tag |
|
|
16
|
+
| `workers-start/cache` | `withEdgeCache`, `sharedMaxAge`, `withoutBrowserMaxAge` | Rendered pages kept in the Workers Cache API |
|
|
17
|
+
| `workers-start/workers` | `getBinding`, `getEnvString`, `afterResponse`, `isKvNamespace` | Bindings and `waitUntil` without a static `cloudflare:workers` import |
|
|
18
|
+
| `workers-start/seo` | `sitemapXml`, `robotsTxt`, `escapeXml` | `/sitemap.xml` and `/robots.txt` bodies |
|
|
19
|
+
| `workers-start/accept` | `parseAccept`, `quality` | Accept header parsing |
|
|
20
|
+
| `workers-start/check-bundle` | `workers-start-check-bundle` (bin) | Fails a build that would ship a local secret |
|
|
21
|
+
|
|
7
22
|
## Why
|
|
8
23
|
|
|
9
24
|
This came out of moving my sites from Next.js on OpenNext to TanStack Start on Workers. Each migration hit the same problems, and each app had started to solve them its own way:
|
|
@@ -137,8 +152,33 @@ In tests, `setWorkersModule({ env, waitUntil })` stands in for the runtime. Unde
|
|
|
137
152
|
- `analyticsScript({ measurementId, hosts })` loads GA4 only on the listed hostnames, so local dev and preview deploys never report. `skipPaths` keeps it off paths like `/admin`, and `consentCookie` waits for a consent cookie.
|
|
138
153
|
- `tagManagerScript({ containerId, hosts })` does the same for a Google Tag Manager container (`GTM-…`): it pushes the `gtm.js` start event and loads `gtm.js` only on the listed hostnames, with the same `skipPaths` and `consentCookie` options. The `<noscript>` iframe fallback is not included.
|
|
139
154
|
|
|
155
|
+
`gaEvent(name, params)` sends an event from the browser: through the `gtag` that `analyticsScript` defines, or as `{ event, ...params }` on a Tag Manager `dataLayer`. Where neither bootstrap ran (local dev, a skipped path, an ad blocker) it does nothing, so callers need no guard or `window.gtag` type of their own.
|
|
156
|
+
|
|
157
|
+
```ts
|
|
158
|
+
import { gaEvent } from "workers-start/scripts";
|
|
159
|
+
|
|
160
|
+
gaEvent("sign_up", { method: "email" });
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
To render JSON-LD in the page body rather than through `head()`, use the same escaping: `<script type="application/ld+json" dangerouslySetInnerHTML={{ __html: jsonLdScript(data).children }} />`. Never put a bare `JSON.stringify` inside a script tag: a value containing `</script>` ends it.
|
|
164
|
+
|
|
140
165
|
Every value is embedded with `inlineJson`, which escapes `<`, `>`, `&`, U+2028 and U+2029, so no option can close the script tag. `jsonLdScript` escapes its body the same way.
|
|
141
166
|
|
|
167
|
+
## Edge page cache
|
|
168
|
+
|
|
169
|
+
A Worker on a custom domain runs ahead of the zone cache, so Cache Rules never see its pages. `withEdgeCache` keeps rendered pages in the Workers Cache API instead: a GET 200 whose `Cache-Control` has `s-maxage` and no `Set-Cookie` is stored for that long, keyed by URL, and later GETs are answered without rendering.
|
|
170
|
+
|
|
171
|
+
```ts
|
|
172
|
+
import { withEdgeCache } from "workers-start/cache";
|
|
173
|
+
|
|
174
|
+
// in the Worker's fetch, around the Start handler
|
|
175
|
+
return withEdgeCache(request, () => handler.fetch(request), {
|
|
176
|
+
version: BUILD_ID, // a new deploy never serves the previous build's HTML
|
|
177
|
+
});
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
A cache hit has its browser `max-age` removed (the zone adds one, and a browser holding page HTML that long outlives the next deploy's assets). The store runs after the response through `afterResponse`; pass `waitUntil` or `cache` to override, as tests do. Outside workerd every request renders.
|
|
181
|
+
|
|
142
182
|
## Sitemap and robots.txt
|
|
143
183
|
|
|
144
184
|
`workers-start/seo` builds the bodies for `/sitemap.xml` and `/robots.txt` routes. The entries and options take the same shape as Next's `MetadataRoute.Sitemap` and `MetadataRoute.Robots`.
|
|
@@ -188,7 +228,7 @@ The same check is exported from `workers-start/check-bundle` as `checkBundle(env
|
|
|
188
228
|
|
|
189
229
|
## Related
|
|
190
230
|
|
|
191
|
-
[`workers-jobs`](https://github.com/ryanio/workers-jobs) runs background jobs on Cron Triggers and Workflows, with dedup, explicit retries, a run ledger and a backstop for missed cron slots.
|
|
231
|
+
[`workers-jobs`](https://github.com/ryanio/workers-kit/tree/main/packages/jobs) runs background jobs on Cron Triggers and Workflows, with dedup, explicit retries, a run ledger and a backstop for missed cron slots.
|
|
192
232
|
|
|
193
233
|
## License
|
|
194
234
|
|
package/dist/cache.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An edge page cache on the Workers Cache API. A Worker on a custom domain runs
|
|
3
|
+
* ahead of the zone cache, so a zone Cache Rule never sees its pages; this
|
|
4
|
+
* keeps rendered pages in the data center's cache instead.
|
|
5
|
+
*
|
|
6
|
+
* A GET 200 whose Cache-Control carries `s-maxage` and sets no cookie is
|
|
7
|
+
* stored for that long, keyed by URL (plus `version`, when given), and later
|
|
8
|
+
* GETs for the same URL are answered from the cache without rendering. Outside
|
|
9
|
+
* workerd, or with no `waitUntil`, every request renders.
|
|
10
|
+
*/
|
|
11
|
+
export interface EdgeCacheOptions {
|
|
12
|
+
/**
|
|
13
|
+
* Added to the cache key, so a deploy never serves a page cached by the
|
|
14
|
+
* previous build (whose HTML names asset files the deploy deleted). Pass a
|
|
15
|
+
* build id or version.
|
|
16
|
+
*/
|
|
17
|
+
version?: string;
|
|
18
|
+
/**
|
|
19
|
+
* The Cache to use. Default `caches.default`. Tests pass a stand-in.
|
|
20
|
+
*/
|
|
21
|
+
cache?: Pick<Cache, "match" | "put">;
|
|
22
|
+
/**
|
|
23
|
+
* Schedules the store after the response. Default `afterResponse` from
|
|
24
|
+
* `workers-start/workers`, which uses the request's `waitUntil` in workerd.
|
|
25
|
+
*/
|
|
26
|
+
waitUntil?: (work: Promise<unknown>) => void;
|
|
27
|
+
}
|
|
28
|
+
/** Seconds a shared cache may keep this response (`s-maxage`), or 0. */
|
|
29
|
+
export declare function sharedMaxAge(response: Response): number;
|
|
30
|
+
/**
|
|
31
|
+
* A copy of `response` without a browser `max-age`. A response read back from
|
|
32
|
+
* the Cache API carries the zone's Browser Cache TTL as `max-age`, and a
|
|
33
|
+
* browser holding page HTML that long outlives the next deploy.
|
|
34
|
+
*/
|
|
35
|
+
export declare function withoutBrowserMaxAge(response: Response): Response;
|
|
36
|
+
/**
|
|
37
|
+
* Answers a GET from the edge cache, or renders and stores the page when its
|
|
38
|
+
* Cache-Control allows a shared cache to keep it.
|
|
39
|
+
*/
|
|
40
|
+
export declare function withEdgeCache(request: Request, render: () => Promise<Response>, options?: EdgeCacheOptions): Promise<Response>;
|
|
41
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,KAAK,CAAC,EAAE,IAAI,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,CAAC,CAAC;IACrC;;;OAGG;IACH,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC;CAC9C;AAKD,wEAAwE;AACxE,wBAAgB,YAAY,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAGvD;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,GAAG,QAAQ,CAajE;AAMD;;;GAGG;AACH,wBAAsB,aAAa,CACjC,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,OAAO,CAAC,QAAQ,CAAC,EAC/B,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,QAAQ,CAAC,CAsBnB"}
|
package/dist/cache.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An edge page cache on the Workers Cache API. A Worker on a custom domain runs
|
|
3
|
+
* ahead of the zone cache, so a zone Cache Rule never sees its pages; this
|
|
4
|
+
* keeps rendered pages in the data center's cache instead.
|
|
5
|
+
*
|
|
6
|
+
* A GET 200 whose Cache-Control carries `s-maxage` and sets no cookie is
|
|
7
|
+
* stored for that long, keyed by URL (plus `version`, when given), and later
|
|
8
|
+
* GETs for the same URL are answered from the cache without rendering. Outside
|
|
9
|
+
* workerd, or with no `waitUntil`, every request renders.
|
|
10
|
+
*/
|
|
11
|
+
import { afterResponse } from "./workers.js";
|
|
12
|
+
const S_MAXAGE = /(?:^|,)\s*s-maxage=(\d+)/;
|
|
13
|
+
const BROWSER_MAX_AGE = /(^|,)\s*max-age=\d+\s*(,|$)/;
|
|
14
|
+
/** Seconds a shared cache may keep this response (`s-maxage`), or 0. */
|
|
15
|
+
export function sharedMaxAge(response) {
|
|
16
|
+
const match = response.headers.get("cache-control")?.match(S_MAXAGE);
|
|
17
|
+
return match ? Number(match[1]) : 0;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A copy of `response` without a browser `max-age`. A response read back from
|
|
21
|
+
* the Cache API carries the zone's Browser Cache TTL as `max-age`, and a
|
|
22
|
+
* browser holding page HTML that long outlives the next deploy.
|
|
23
|
+
*/
|
|
24
|
+
export function withoutBrowserMaxAge(response) {
|
|
25
|
+
const cacheControl = response.headers.get("cache-control");
|
|
26
|
+
if (!(cacheControl && BROWSER_MAX_AGE.test(cacheControl)))
|
|
27
|
+
return response;
|
|
28
|
+
const headers = new Headers(response.headers);
|
|
29
|
+
headers.set("Cache-Control", cacheControl
|
|
30
|
+
.replace(BROWSER_MAX_AGE, (_m, before, after) => before && after ? "," : "")
|
|
31
|
+
.trim());
|
|
32
|
+
return new Response(response.body, { status: response.status, headers });
|
|
33
|
+
}
|
|
34
|
+
function defaultCache() {
|
|
35
|
+
return globalThis.caches?.default;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Answers a GET from the edge cache, or renders and stores the page when its
|
|
39
|
+
* Cache-Control allows a shared cache to keep it.
|
|
40
|
+
*/
|
|
41
|
+
export async function withEdgeCache(request, render, options = {}) {
|
|
42
|
+
const cache = options.cache ?? defaultCache();
|
|
43
|
+
if (!cache || request.method !== "GET")
|
|
44
|
+
return render();
|
|
45
|
+
const keyUrl = new URL(request.url);
|
|
46
|
+
if (options.version)
|
|
47
|
+
keyUrl.searchParams.set("__build", options.version);
|
|
48
|
+
const key = new Request(keyUrl.toString(), { method: "GET" });
|
|
49
|
+
const hit = await cache.match(key);
|
|
50
|
+
if (hit)
|
|
51
|
+
return withoutBrowserMaxAge(hit);
|
|
52
|
+
const response = await render();
|
|
53
|
+
if (response.status === 200 &&
|
|
54
|
+
sharedMaxAge(response) > 0 &&
|
|
55
|
+
!response.headers.has("set-cookie")) {
|
|
56
|
+
const store = cache.put(key, response.clone());
|
|
57
|
+
if (options.waitUntil)
|
|
58
|
+
options.waitUntil(store);
|
|
59
|
+
else
|
|
60
|
+
void afterResponse(store);
|
|
61
|
+
}
|
|
62
|
+
return response;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAoB7C,MAAM,QAAQ,GAAG,0BAA0B,CAAC;AAC5C,MAAM,eAAe,GAAG,6BAA6B,CAAC;AAEtD,wEAAwE;AACxE,MAAM,UAAU,YAAY,CAAC,QAAkB;IAC7C,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;IACrE,OAAO,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACtC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,QAAkB;IACrD,MAAM,YAAY,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAC3D,IAAI,CAAC,CAAC,YAAY,IAAI,eAAe,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAAE,OAAO,QAAQ,CAAC;IAC3E,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC9C,OAAO,CAAC,GAAG,CACT,eAAe,EACf,YAAY;SACT,OAAO,CAAC,eAAe,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,CAC9C,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAC3B;SACA,IAAI,EAAE,CACV,CAAC;IACF,OAAO,IAAI,QAAQ,CAAC,QAAQ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C,SAAS,CAAC,KAAK,CAAC,CAAC;;YAC3C,KAAK,aAAa,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
package/dist/check-bundle.d.ts
CHANGED
|
@@ -6,8 +6,6 @@
|
|
|
6
6
|
* and in the encodings a bundler or a URL would give it. A match means a key
|
|
7
7
|
* reached something that ships, whichever tool put it there.
|
|
8
8
|
*/
|
|
9
|
-
/** Values shorter than this are flags or placeholders, not secrets. */
|
|
10
|
-
export declare const MIN_SECRET_LENGTH = 12;
|
|
11
9
|
/**
|
|
12
10
|
* Paths, relative to a build directory, that are never uploaded: the copy of
|
|
13
11
|
* the local env the Cloudflare Vite plugin writes for `vite preview`.
|
|
@@ -21,8 +19,6 @@ export declare const DEFAULT_PUBLIC_PREFIXES: string[];
|
|
|
21
19
|
* literally, double quotes with `\n` escapes and multi-line values.
|
|
22
20
|
*/
|
|
23
21
|
export declare function parseEnvFile(source: string): [string, string][];
|
|
24
|
-
/** The forms a value can take once it is in a bundle or a URL. */
|
|
25
|
-
export declare function encodings(value: string): string[];
|
|
26
22
|
export interface LeakOptions {
|
|
27
23
|
/** Keys whose values are public. Matched exactly. */
|
|
28
24
|
allow?: readonly string[];
|
|
@@ -31,16 +27,6 @@ export interface LeakOptions {
|
|
|
31
27
|
}
|
|
32
28
|
/** The env keys whose values appear, in any encoding, in any of the given file contents. */
|
|
33
29
|
export declare function leakedKeys(pairs: [string, string][], contents: string[], options?: LeakOptions): string[];
|
|
34
|
-
/** Every KEY=value pair in the local env files of one or more directories. */
|
|
35
|
-
export declare function localEnvPairs(dirs: string | readonly string[]): [string, string][];
|
|
36
|
-
/**
|
|
37
|
-
* Every regular file under `dir`, recursively. Symlinks are skipped, so the
|
|
38
|
-
* walk never loops or leaves the directory. `skip` holds paths relative to
|
|
39
|
-
* `dir`, with forward slashes.
|
|
40
|
-
*/
|
|
41
|
-
export declare function listFiles(dir: string, skip?: readonly string[]): string[];
|
|
42
|
-
/** File contents as text, decompressing `.gz` and `.br` files. */
|
|
43
|
-
export declare function readBuilt(path: string): string;
|
|
44
30
|
export interface CheckResult {
|
|
45
31
|
envValues: number;
|
|
46
32
|
files: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check-bundle.d.ts","sourceRoot":"","sources":["../src/check-bundle.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;
|
|
1
|
+
{"version":3,"file":"check-bundle.d.ts","sourceRoot":"","sources":["../src/check-bundle.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AASH;;;GAGG;AACH,eAAO,MAAM,YAAY,UAAuB,CAAC;AAEjD,6DAA6D;AAC7D,eAAO,MAAM,uBAAuB,UAAY,CAAC;AAcjD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CA+B/D;AA6BD,MAAM,WAAW,WAAW;IAC1B,qDAAqD;IACrD,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1B,iEAAiE;IACjE,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACpC;AAED,4FAA4F;AAC5F,wBAAgB,UAAU,CACxB,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,EACzB,QAAQ,EAAE,MAAM,EAAE,EAClB,OAAO,GAAE,WAAgB,GACxB,MAAM,EAAE,CAmBV;AAuDD,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,MAAM,WAAW,YAAa,SAAQ,WAAW;IAC/C,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC1B;AAED;;;GAGG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,EACnC,KAAK,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,EACjC,OAAO,GAAE,YAAiB,GACzB,WAAW,CAkBb"}
|
package/dist/check-bundle.js
CHANGED
|
@@ -10,7 +10,7 @@ import { existsSync, lstatSync, readdirSync, readFileSync } from "node:fs";
|
|
|
10
10
|
import { join, relative, sep } from "node:path";
|
|
11
11
|
import { brotliDecompressSync, gunzipSync } from "node:zlib";
|
|
12
12
|
/** Values shorter than this are flags or placeholders, not secrets. */
|
|
13
|
-
|
|
13
|
+
const MIN_SECRET_LENGTH = 12;
|
|
14
14
|
/**
|
|
15
15
|
* Paths, relative to a build directory, that are never uploaded: the copy of
|
|
16
16
|
* the local env the Cloudflare Vite plugin writes for `vite preview`.
|
|
@@ -82,7 +82,7 @@ function hasClosingQuote(body, quote) {
|
|
|
82
82
|
return closingQuoteIndex(body, quote) !== -1;
|
|
83
83
|
}
|
|
84
84
|
/** The forms a value can take once it is in a bundle or a URL. */
|
|
85
|
-
|
|
85
|
+
function encodings(value) {
|
|
86
86
|
const forms = new Set([
|
|
87
87
|
value,
|
|
88
88
|
encodeURIComponent(value),
|
|
@@ -112,7 +112,7 @@ export function leakedKeys(pairs, contents, options = {}) {
|
|
|
112
112
|
return [...leaked].sort();
|
|
113
113
|
}
|
|
114
114
|
/** Every KEY=value pair in the local env files of one or more directories. */
|
|
115
|
-
|
|
115
|
+
function localEnvPairs(dirs) {
|
|
116
116
|
return (typeof dirs === "string" ? [dirs] : dirs).flatMap((dir) => readdirSync(dir)
|
|
117
117
|
.filter((name) => ENV_FILE.test(name) && !NOT_SECRETS.test(name))
|
|
118
118
|
.flatMap((name) => parseEnvFile(readFileSync(join(dir, name), "utf8"))));
|
|
@@ -122,7 +122,7 @@ export function localEnvPairs(dirs) {
|
|
|
122
122
|
* walk never loops or leaves the directory. `skip` holds paths relative to
|
|
123
123
|
* `dir`, with forward slashes.
|
|
124
124
|
*/
|
|
125
|
-
|
|
125
|
+
function listFiles(dir, skip = DEFAULT_SKIP) {
|
|
126
126
|
const files = [];
|
|
127
127
|
const walk = (current) => {
|
|
128
128
|
for (const name of readdirSync(current)) {
|
|
@@ -144,7 +144,7 @@ export function listFiles(dir, skip = DEFAULT_SKIP) {
|
|
|
144
144
|
return files;
|
|
145
145
|
}
|
|
146
146
|
/** File contents as text, decompressing `.gz` and `.br` files. */
|
|
147
|
-
|
|
147
|
+
function readBuilt(path) {
|
|
148
148
|
const bytes = readFileSync(path);
|
|
149
149
|
try {
|
|
150
150
|
if (path.endsWith(".gz"))
|
package/dist/check-bundle.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check-bundle.js","sourceRoot":"","sources":["../src/check-bundle.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC3E,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE7D,uEAAuE;AACvE,MAAM,
|
|
1
|
+
{"version":3,"file":"check-bundle.js","sourceRoot":"","sources":["../src/check-bundle.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC3E,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE7D,uEAAuE;AACvE,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAE7B;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,kBAAkB,CAAC,CAAC;AAEjD,6DAA6D;AAC7D,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,OAAO,CAAC,CAAC;AAEjD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GAAiB,EAAE;IAE1B,MAAM,IAAI,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IACzD,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,GAAG,GAAG,+BAA+B,CAAC,CAAC;QACzD,CAAC;IACH,CAAC;IACD,KAAK,MAAM,GAAG,IAAI,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;QACpE,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,iBAAiB,GAAG,kBAAkB,CAAC,CAAC;QAC1D,CAAC;IACH,CAAC;IACD,MAAM,KAAK,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;IACrC,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CACjC,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,IAAI,YAAY,CAAC,CAC7C,CAAC;IACF,MAAM,MAAM,GAAG,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,CAAC;IAChE,OAAO,EAAE,SAAS,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;AAClE,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
export type { MediaRange } from "./accept.js";
|
|
2
2
|
export { parseAccept, quality } from "./accept.js";
|
|
3
|
+
export type { EdgeCacheOptions } from "./cache.js";
|
|
4
|
+
export { sharedMaxAge, withEdgeCache, withoutBrowserMaxAge, } from "./cache.js";
|
|
3
5
|
export type { EntryOptions, FetchHandler, MarkdownPage, MarkdownResult, } from "./entry.js";
|
|
4
6
|
export { acceptsHtml, createEntry, defaultIsPage, MARKDOWN_HEADERS, mergeVary, normalizePath, underPrefix, wantsMarkdown, withHeaders, } from "./entry.js";
|
|
5
7
|
export type { HeadLink, HeadScript, HeadTags, MetaTag, PageImage, PageSeo, SiteHead, } from "./head.js";
|
|
6
8
|
export { createPageHead, jsonLdScript } from "./head.js";
|
|
7
|
-
export type { AnalyticsScriptOptions, TagManagerScriptOptions, ThemeScriptOptions, } from "./scripts.js";
|
|
8
|
-
export { analyticsScript, inlineJson, tagManagerScript, themeScript, } from "./scripts.js";
|
|
9
|
+
export type { AnalyticsScriptOptions, GaEventParams, TagManagerScriptOptions, ThemeScriptOptions, } from "./scripts.js";
|
|
10
|
+
export { analyticsScript, gaEvent, inlineJson, tagManagerScript, themeScript, } from "./scripts.js";
|
|
9
11
|
export type { RobotsOptions, RobotsRule, SitemapEntry } from "./seo.js";
|
|
10
12
|
export { escapeXml, robotsTxt, sitemapXml } from "./seo.js";
|
|
11
13
|
export type { WorkersModule } from "./workers.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACnD,YAAY,EACV,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,cAAc,GACf,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,WAAW,EACX,WAAW,EACX,aAAa,EACb,gBAAgB,EAChB,SAAS,EACT,aAAa,EACb,WAAW,EACX,aAAa,EACb,WAAW,GACZ,MAAM,YAAY,CAAC;AACpB,YAAY,EACV,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,OAAO,EACP,SAAS,EAC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,YAAY,EAAE,MAAM,WAAW,CAAC;AACzD,YAAY,EACV,sBAAsB,EACtB,aAAa,EACb,uBAAuB,EACvB,kBAAkB,GACnB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,eAAe,EACf,OAAO,EACP,UAAU,EACV,gBAAgB,EAChB,WAAW,GACZ,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC5D,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EACL,aAAa,EACb,UAAU,EACV,YAAY,EACZ,aAAa,EACb,WAAW,EACX,gBAAgB,GACjB,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export { parseAccept, quality } from "./accept.js";
|
|
2
|
+
export { sharedMaxAge, withEdgeCache, withoutBrowserMaxAge, } from "./cache.js";
|
|
2
3
|
export { acceptsHtml, createEntry, defaultIsPage, MARKDOWN_HEADERS, mergeVary, normalizePath, underPrefix, wantsMarkdown, withHeaders, } from "./entry.js";
|
|
3
4
|
export { createPageHead, jsonLdScript } from "./head.js";
|
|
4
|
-
export { analyticsScript, inlineJson, tagManagerScript, themeScript, } from "./scripts.js";
|
|
5
|
+
export { analyticsScript, gaEvent, inlineJson, tagManagerScript, themeScript, } from "./scripts.js";
|
|
5
6
|
export { escapeXml, robotsTxt, sitemapXml } from "./seo.js";
|
|
6
7
|
export { afterResponse, getBinding, getEnvString, isKvNamespace, loadWorkers, setWorkersModule, } from "./workers.js";
|
|
7
8
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,EACL,YAAY,EACZ,aAAa,EACb,oBAAoB,GACrB,MAAM,YAAY,CAAC;AAOpB,OAAO,EACL,WAAW,EACX,WAAW,EACX,aAAa,EACb,gBAAgB,EAChB,SAAS,EACT,aAAa,EACb,WAAW,EACX,aAAa,EACb,WAAW,GACZ,MAAM,YAAY,CAAC;AAUpB,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAOzD,OAAO,EACL,eAAe,EACf,OAAO,EACP,UAAU,EACV,gBAAgB,EAChB,WAAW,GACZ,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE5D,OAAO,EACL,aAAa,EACb,UAAU,EACV,YAAY,EACZ,aAAa,EACb,WAAW,EACX,gBAAgB,GACjB,MAAM,cAAc,CAAC"}
|
package/dist/scripts.d.ts
CHANGED
|
@@ -66,4 +66,14 @@ export interface TagManagerScriptOptions extends Omit<AnalyticsScriptOptions, "m
|
|
|
66
66
|
* the listed hosts load gtm.js, so local dev and previews never fire tags.
|
|
67
67
|
*/
|
|
68
68
|
export declare function tagManagerScript(options: TagManagerScriptOptions): string;
|
|
69
|
+
/** Event parameters GA4 accepts: strings, numbers and booleans. */
|
|
70
|
+
export type GaEventParams = Record<string, string | number | boolean | undefined>;
|
|
71
|
+
/**
|
|
72
|
+
* Sends an analytics event. With `analyticsScript` it calls the `gtag` the
|
|
73
|
+
* bootstrap defines; with `tagManagerScript` (no `gtag`) it pushes
|
|
74
|
+
* `{ event: name, ...params }` to the container's `dataLayer`. It does nothing
|
|
75
|
+
* on the server, or where neither bootstrap ran (a skipped host or path, an
|
|
76
|
+
* ad blocker), so callers need no guard.
|
|
77
|
+
*/
|
|
78
|
+
export declare function gaEvent(name: string, params?: GaEventParams): void;
|
|
69
79
|
//# sourceMappingURL=scripts.d.ts.map
|
package/dist/scripts.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scripts.d.ts","sourceRoot":"","sources":["../src/scripts.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAOjD;AAED,MAAM,WAAW,kBAAkB;IACjC,yCAAyC;IACzC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,2DAA2D;IAC3D,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB;;;;OAIG;IACH,MAAM,CAAC,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,KAAK,EAAE,IAAI,CAAA;KAAE,CAAC;IACjD;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,OAAO,GAAE,kBAAuB,GAAG,MAAM,CAYpE;AAED,MAAM,WAAW,sBAAsB;IACrC,6DAA6D;IAC7D,aAAa,EAAE,MAAM,CAAC;IACtB,0GAA0G;IAC1G,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,iEAAiE;IACjE,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB;;;OAGG;IACH,aAAa,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAClD;AA6BD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,MAAM,CAMvE;AAED,MAAM,WAAW,uBACf,SAAQ,IAAI,CAAC,sBAAsB,EAAE,eAAe,CAAC;IACrD,4EAA4E;IAC5E,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AAC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AAM,MAAM,aAAa,GAAG,MAAM,CAChC,MAAM,EACN,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CACtC,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,GAAE,aAAkB,GAAG,IAAI,CAStE"}
|
package/dist/scripts.js
CHANGED
|
@@ -72,4 +72,20 @@ export function tagManagerScript(options) {
|
|
|
72
72
|
const id = inlineJson(options.containerId);
|
|
73
73
|
return `(function(){${gateChecks(options)}window.dataLayer=window.dataLayer||[];window.dataLayer.push({"gtm.start":new Date().getTime(),event:"gtm.js"});var s=document.createElement("script");s.async=true;s.src="https://www.googletagmanager.com/gtm.js?id="+${id};document.head.appendChild(s);})();`;
|
|
74
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Sends an analytics event. With `analyticsScript` it calls the `gtag` the
|
|
77
|
+
* bootstrap defines; with `tagManagerScript` (no `gtag`) it pushes
|
|
78
|
+
* `{ event: name, ...params }` to the container's `dataLayer`. It does nothing
|
|
79
|
+
* on the server, or where neither bootstrap ran (a skipped host or path, an
|
|
80
|
+
* ad blocker), so callers need no guard.
|
|
81
|
+
*/
|
|
82
|
+
export function gaEvent(name, params = {}) {
|
|
83
|
+
if (typeof window === "undefined")
|
|
84
|
+
return;
|
|
85
|
+
const w = window;
|
|
86
|
+
if (typeof w.gtag === "function")
|
|
87
|
+
w.gtag("event", name, params);
|
|
88
|
+
else if (Array.isArray(w.dataLayer))
|
|
89
|
+
w.dataLayer.push({ event: name, ...params });
|
|
90
|
+
}
|
|
75
91
|
//# sourceMappingURL=scripts.js.map
|
package/dist/scripts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scripts.js","sourceRoot":"","sources":["../src/scripts.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,OAAO,IAAI,CAAC,SAAS,CA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C,CAAC;IAC7C,OAAO,eAAe,UAAU,CAAC,OAAO,CAAC,4GAA4G,EAAE,8KAA8K,EAAE,SAAS,CAAC;AACnV,CAAC;AAQD;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAgC;IAC/D,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;QACjD,MAAM,IAAI,KAAK,CAAC,mCAAmC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;IAC5E,CAAC;IACD,MAAM,EAAE,GAAG,UAAU,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAC3C,OAAO,eAAe,UAAU,CAAC,OAAO,CAAC,0NAA0N,EAAE,qCAAqC,CAAC;AAC7S,CAAC;AAQD;;;;;;GAMG;AACH,MAAM,UAAU,OAAO,CAAC,IAAY,EAAE,MAAM,GAAkB,EAAE;IAC9D,IAAI,OAAO,MAAM,KAAK,WAAW;QAAE,OAAO;IAC1C,MAAM,CAAC,GAAG,MAGT,CAAC;IACF,IAAI,OAAO,CAAC,CAAC,IAAI,KAAK,UAAU;QAAE,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;SAC3D,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;QACjC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;AACjD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "workers-start",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "The parts every TanStack Start app on Cloudflare Workers ends up writing: Markdown for agents on the same URL, a head helper that stops share cards leaking between pages, lazy Workers bindings, and a check that no local secret ships in the build.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Ryan Ghods",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/ryanio/workers-
|
|
9
|
+
"url": "git+https://github.com/ryanio/workers-kit.git",
|
|
10
|
+
"directory": "packages/start"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/ryanio/workers-kit/tree/main/packages/start#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/ryanio/workers-kit/issues"
|
|
10
15
|
},
|
|
11
16
|
"keywords": [
|
|
12
17
|
"cloudflare",
|
|
@@ -41,6 +46,11 @@
|
|
|
41
46
|
"import": "./dist/workers.js",
|
|
42
47
|
"default": "./dist/workers.js"
|
|
43
48
|
},
|
|
49
|
+
"./cache": {
|
|
50
|
+
"types": "./dist/cache.d.ts",
|
|
51
|
+
"import": "./dist/cache.js",
|
|
52
|
+
"default": "./dist/cache.js"
|
|
53
|
+
},
|
|
44
54
|
"./scripts": {
|
|
45
55
|
"types": "./dist/scripts.d.ts",
|
|
46
56
|
"import": "./dist/scripts.js",
|
|
@@ -79,23 +89,15 @@
|
|
|
79
89
|
"scripts": {
|
|
80
90
|
"build": "rm -rf dist && tsc -p tsconfig.build.json && chmod +x dist/check-bundle-cli.js",
|
|
81
91
|
"typecheck": "tsc --noEmit",
|
|
82
|
-
"lint": "biome check",
|
|
83
|
-
"format": "biome check --write",
|
|
84
92
|
"test": "npm run build && vitest run",
|
|
85
|
-
"check": "npm run
|
|
86
|
-
"prepack": "npm run build"
|
|
87
|
-
"prepare": "git config core.hooksPath .githooks || true",
|
|
88
|
-
"deadcode": "knip",
|
|
89
|
-
"check:doc-refs": "node scripts/doc-refs/doc-refs.mjs",
|
|
90
|
-
"check:lockfile": "node scripts/check-lockfile-platforms.mjs"
|
|
93
|
+
"check": "npm run typecheck && npm run build && vitest run",
|
|
94
|
+
"prepack": "npm run build"
|
|
91
95
|
},
|
|
92
96
|
"publishConfig": {
|
|
93
97
|
"access": "public"
|
|
94
98
|
},
|
|
95
99
|
"devDependencies": {
|
|
96
|
-
"@biomejs/biome": "^2.6.8",
|
|
97
100
|
"@types/node": "^24.19.2",
|
|
98
|
-
"knip": "^6.47.0",
|
|
99
101
|
"typescript": "^7.0.2",
|
|
100
102
|
"vitest": "^5.1.0"
|
|
101
103
|
}
|
package/src/cache.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An edge page cache on the Workers Cache API. A Worker on a custom domain runs
|
|
3
|
+
* ahead of the zone cache, so a zone Cache Rule never sees its pages; this
|
|
4
|
+
* keeps rendered pages in the data center's cache instead.
|
|
5
|
+
*
|
|
6
|
+
* A GET 200 whose Cache-Control carries `s-maxage` and sets no cookie is
|
|
7
|
+
* stored for that long, keyed by URL (plus `version`, when given), and later
|
|
8
|
+
* GETs for the same URL are answered from the cache without rendering. Outside
|
|
9
|
+
* workerd, or with no `waitUntil`, every request renders.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { afterResponse } from "./workers.js";
|
|
13
|
+
|
|
14
|
+
export interface EdgeCacheOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Added to the cache key, so a deploy never serves a page cached by the
|
|
17
|
+
* previous build (whose HTML names asset files the deploy deleted). Pass a
|
|
18
|
+
* build id or version.
|
|
19
|
+
*/
|
|
20
|
+
version?: string;
|
|
21
|
+
/**
|
|
22
|
+
* The Cache to use. Default `caches.default`. Tests pass a stand-in.
|
|
23
|
+
*/
|
|
24
|
+
cache?: Pick<Cache, "match" | "put">;
|
|
25
|
+
/**
|
|
26
|
+
* Schedules the store after the response. Default `afterResponse` from
|
|
27
|
+
* `workers-start/workers`, which uses the request's `waitUntil` in workerd.
|
|
28
|
+
*/
|
|
29
|
+
waitUntil?: (work: Promise<unknown>) => void;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const S_MAXAGE = /(?:^|,)\s*s-maxage=(\d+)/;
|
|
33
|
+
const BROWSER_MAX_AGE = /(^|,)\s*max-age=\d+\s*(,|$)/;
|
|
34
|
+
|
|
35
|
+
/** Seconds a shared cache may keep this response (`s-maxage`), or 0. */
|
|
36
|
+
export function sharedMaxAge(response: Response): number {
|
|
37
|
+
const match = response.headers.get("cache-control")?.match(S_MAXAGE);
|
|
38
|
+
return match ? Number(match[1]) : 0;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* A copy of `response` without a browser `max-age`. A response read back from
|
|
43
|
+
* the Cache API carries the zone's Browser Cache TTL as `max-age`, and a
|
|
44
|
+
* browser holding page HTML that long outlives the next deploy.
|
|
45
|
+
*/
|
|
46
|
+
export function withoutBrowserMaxAge(response: Response): Response {
|
|
47
|
+
const cacheControl = response.headers.get("cache-control");
|
|
48
|
+
if (!(cacheControl && BROWSER_MAX_AGE.test(cacheControl))) return response;
|
|
49
|
+
const headers = new Headers(response.headers);
|
|
50
|
+
headers.set(
|
|
51
|
+
"Cache-Control",
|
|
52
|
+
cacheControl
|
|
53
|
+
.replace(BROWSER_MAX_AGE, (_m, before, after) =>
|
|
54
|
+
before && after ? "," : "",
|
|
55
|
+
)
|
|
56
|
+
.trim(),
|
|
57
|
+
);
|
|
58
|
+
return new Response(response.body, { status: response.status, headers });
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function defaultCache(): Pick<Cache, "match" | "put"> | undefined {
|
|
62
|
+
return (globalThis as { caches?: { default?: Cache } }).caches?.default;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Answers a GET from the edge cache, or renders and stores the page when its
|
|
67
|
+
* Cache-Control allows a shared cache to keep it.
|
|
68
|
+
*/
|
|
69
|
+
export async function withEdgeCache(
|
|
70
|
+
request: Request,
|
|
71
|
+
render: () => Promise<Response>,
|
|
72
|
+
options: EdgeCacheOptions = {},
|
|
73
|
+
): Promise<Response> {
|
|
74
|
+
const cache = options.cache ?? defaultCache();
|
|
75
|
+
if (!cache || request.method !== "GET") return render();
|
|
76
|
+
|
|
77
|
+
const keyUrl = new URL(request.url);
|
|
78
|
+
if (options.version) keyUrl.searchParams.set("__build", options.version);
|
|
79
|
+
const key = new Request(keyUrl.toString(), { method: "GET" });
|
|
80
|
+
|
|
81
|
+
const hit = await cache.match(key);
|
|
82
|
+
if (hit) return withoutBrowserMaxAge(hit);
|
|
83
|
+
|
|
84
|
+
const response = await render();
|
|
85
|
+
if (
|
|
86
|
+
response.status === 200 &&
|
|
87
|
+
sharedMaxAge(response) > 0 &&
|
|
88
|
+
!response.headers.has("set-cookie")
|
|
89
|
+
) {
|
|
90
|
+
const store = cache.put(key, response.clone());
|
|
91
|
+
if (options.waitUntil) options.waitUntil(store);
|
|
92
|
+
else void afterResponse(store);
|
|
93
|
+
}
|
|
94
|
+
return response;
|
|
95
|
+
}
|
package/src/check-bundle.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { join, relative, sep } from "node:path";
|
|
|
12
12
|
import { brotliDecompressSync, gunzipSync } from "node:zlib";
|
|
13
13
|
|
|
14
14
|
/** Values shorter than this are flags or placeholders, not secrets. */
|
|
15
|
-
|
|
15
|
+
const MIN_SECRET_LENGTH = 12;
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Paths, relative to a build directory, that are never uploaded: the copy of
|
|
@@ -89,7 +89,7 @@ function hasClosingQuote(body: string, quote: string): boolean {
|
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
/** The forms a value can take once it is in a bundle or a URL. */
|
|
92
|
-
|
|
92
|
+
function encodings(value: string): string[] {
|
|
93
93
|
const forms = new Set([
|
|
94
94
|
value,
|
|
95
95
|
encodeURIComponent(value),
|
|
@@ -134,9 +134,7 @@ export function leakedKeys(
|
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
/** Every KEY=value pair in the local env files of one or more directories. */
|
|
137
|
-
|
|
138
|
-
dirs: string | readonly string[],
|
|
139
|
-
): [string, string][] {
|
|
137
|
+
function localEnvPairs(dirs: string | readonly string[]): [string, string][] {
|
|
140
138
|
return (typeof dirs === "string" ? [dirs] : dirs).flatMap((dir) =>
|
|
141
139
|
readdirSync(dir)
|
|
142
140
|
.filter((name) => ENV_FILE.test(name) && !NOT_SECRETS.test(name))
|
|
@@ -149,7 +147,7 @@ export function localEnvPairs(
|
|
|
149
147
|
* walk never loops or leaves the directory. `skip` holds paths relative to
|
|
150
148
|
* `dir`, with forward slashes.
|
|
151
149
|
*/
|
|
152
|
-
|
|
150
|
+
function listFiles(
|
|
153
151
|
dir: string,
|
|
154
152
|
skip: readonly string[] = DEFAULT_SKIP,
|
|
155
153
|
): string[] {
|
|
@@ -176,7 +174,7 @@ export function listFiles(
|
|
|
176
174
|
}
|
|
177
175
|
|
|
178
176
|
/** File contents as text, decompressing `.gz` and `.br` files. */
|
|
179
|
-
|
|
177
|
+
function readBuilt(path: string): string {
|
|
180
178
|
const bytes = readFileSync(path);
|
|
181
179
|
try {
|
|
182
180
|
if (path.endsWith(".gz")) return gunzipSync(bytes).toString("latin1");
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
export type { MediaRange } from "./accept.js";
|
|
2
2
|
export { parseAccept, quality } from "./accept.js";
|
|
3
|
+
export type { EdgeCacheOptions } from "./cache.js";
|
|
4
|
+
export {
|
|
5
|
+
sharedMaxAge,
|
|
6
|
+
withEdgeCache,
|
|
7
|
+
withoutBrowserMaxAge,
|
|
8
|
+
} from "./cache.js";
|
|
3
9
|
export type {
|
|
4
10
|
EntryOptions,
|
|
5
11
|
FetchHandler,
|
|
@@ -29,11 +35,13 @@ export type {
|
|
|
29
35
|
export { createPageHead, jsonLdScript } from "./head.js";
|
|
30
36
|
export type {
|
|
31
37
|
AnalyticsScriptOptions,
|
|
38
|
+
GaEventParams,
|
|
32
39
|
TagManagerScriptOptions,
|
|
33
40
|
ThemeScriptOptions,
|
|
34
41
|
} from "./scripts.js";
|
|
35
42
|
export {
|
|
36
43
|
analyticsScript,
|
|
44
|
+
gaEvent,
|
|
37
45
|
inlineJson,
|
|
38
46
|
tagManagerScript,
|
|
39
47
|
themeScript,
|
package/src/scripts.ts
CHANGED
|
@@ -125,3 +125,27 @@ export function tagManagerScript(options: TagManagerScriptOptions): string {
|
|
|
125
125
|
const id = inlineJson(options.containerId);
|
|
126
126
|
return `(function(){${gateChecks(options)}window.dataLayer=window.dataLayer||[];window.dataLayer.push({"gtm.start":new Date().getTime(),event:"gtm.js"});var s=document.createElement("script");s.async=true;s.src="https://www.googletagmanager.com/gtm.js?id="+${id};document.head.appendChild(s);})();`;
|
|
127
127
|
}
|
|
128
|
+
|
|
129
|
+
/** Event parameters GA4 accepts: strings, numbers and booleans. */
|
|
130
|
+
export type GaEventParams = Record<
|
|
131
|
+
string,
|
|
132
|
+
string | number | boolean | undefined
|
|
133
|
+
>;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Sends an analytics event. With `analyticsScript` it calls the `gtag` the
|
|
137
|
+
* bootstrap defines; with `tagManagerScript` (no `gtag`) it pushes
|
|
138
|
+
* `{ event: name, ...params }` to the container's `dataLayer`. It does nothing
|
|
139
|
+
* on the server, or where neither bootstrap ran (a skipped host or path, an
|
|
140
|
+
* ad blocker), so callers need no guard.
|
|
141
|
+
*/
|
|
142
|
+
export function gaEvent(name: string, params: GaEventParams = {}): void {
|
|
143
|
+
if (typeof window === "undefined") return;
|
|
144
|
+
const w = window as {
|
|
145
|
+
gtag?: (...args: unknown[]) => void;
|
|
146
|
+
dataLayer?: unknown[];
|
|
147
|
+
};
|
|
148
|
+
if (typeof w.gtag === "function") w.gtag("event", name, params);
|
|
149
|
+
else if (Array.isArray(w.dataLayer))
|
|
150
|
+
w.dataLayer.push({ event: name, ...params });
|
|
151
|
+
}
|