fondu 0.13.0 → 0.15.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 +1 -1
- package/dist/client/app.d.ts +36 -8
- package/dist/client/app.js +39 -16
- package/dist/client/form.d.ts +3 -1
- package/dist/client/form.js +10 -4
- package/dist/client/navigation.d.ts +4 -1
- package/dist/client/navigation.js +193 -30
- package/dist/client.d.ts +97 -11
- package/dist/client.js +66 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/paths.d.ts +7 -2
- package/dist/paths.js +13 -6
- package/dist/server/app.d.ts +8 -4
- package/dist/server/app.js +38 -24
- package/dist/server/document.d.ts +10 -2
- package/dist/server/document.js +69 -18
- package/dist/server/errors.js +1 -0
- package/dist/server/handler.d.ts +13 -7
- package/dist/server/http.d.ts +2 -0
- package/dist/server/http.js +3 -0
- package/dist/server/prerender.js +7 -52
- package/dist/server/protocol.d.ts +16 -2
- package/dist/server/protocol.js +95 -15
- package/dist/server/routes.d.ts +3 -1
- package/dist/server/routes.js +6 -2
- package/dist/server/static.d.ts +14 -0
- package/dist/server/static.js +37 -0
- package/dist/virtual.d.ts +5 -1
- package/dist/vite/index.js +30 -21
- package/dist/vite/prerender.d.ts +11 -7
- package/dist/vite/prerender.js +13 -10
- package/dist/vite/strip.d.ts +1 -1
- package/dist/vite/strip.js +1 -1
- package/dist/vite/typegen.js +1 -1
- package/package.json +1 -1
package/dist/vite/prerender.js
CHANGED
|
@@ -7,12 +7,11 @@ import { dirname, join, resolve } from 'node:path';
|
|
|
7
7
|
import { pathToFileURL } from 'node:url';
|
|
8
8
|
import { PAGE_DATA, staticFiles } from '../paths.js';
|
|
9
9
|
/** the response headers a static document keeps: the security headers (hono/secure-headers' and the like) */
|
|
10
|
-
const SECURITY_HEADERS = /^(content-security-policy(-report-only)?|strict-transport-security|referrer-policy|permissions-policy|x-content-type-options|x-frame-options|x-xss-protection|x-dns-prefetch-control|x-download-options|x-permitted-cross-domain-policies|origin-agent-cluster|cross-origin-(opener|embedder|resource)-policy)$/i;
|
|
10
|
+
const SECURITY_HEADERS = /^(content-security-policy(-report-only)?|strict-transport-security|referrer-policy|permissions-policy|reporting-endpoints|report-to|x-content-type-options|x-frame-options|x-xss-protection|x-dns-prefetch-control|x-download-options|x-permitted-cross-domain-policies|origin-agent-cluster|cross-origin-(opener|embedder|resource)-policy)$/i;
|
|
11
11
|
/**
|
|
12
|
-
* A static document's own tags: those with the build's nonce (its Content Security Policy's). The
|
|
13
|
-
* document
|
|
14
|
-
*
|
|
15
|
-
* inline scripts.
|
|
12
|
+
* A static document's own tags: those with the build's nonce (its Content Security Policy's). The policy of a static
|
|
13
|
+
* document has no nonce: its inline scripts are allowed by their hashes instead, and only these tags may have had the
|
|
14
|
+
* nonce: a `nonce` the document has otherwise (in a page's markup) is dropped. Then the hashes of these inline scripts.
|
|
16
15
|
*/
|
|
17
16
|
export function ownScripts(html, policy) {
|
|
18
17
|
const nonce = policy?.match(/'nonce-([^']+)'/)?.[1];
|
|
@@ -79,10 +78,11 @@ export function withHeaderRules(file, headers) {
|
|
|
79
78
|
/**
|
|
80
79
|
* After the build: the built server (the Worker in wrangler, or `node` / `bun dist/server/index.js`), started with
|
|
81
80
|
* `FONDU_PRERENDER` set, lists the pages to prerender (`/__fondu/prerender`); each is asked for as a document and as
|
|
82
|
-
* a navigation, and both are written to the client build
|
|
83
|
-
*
|
|
81
|
+
* a navigation, and both are written to the client build, with the security headers the build decided for them: one
|
|
82
|
+
* set, in `_headers` (Cloudflare serves the files before the Worker) or in `prerender.json` next to the built server
|
|
83
|
+
* (Node and Bun: its entry serves the files before the app).
|
|
84
84
|
*/
|
|
85
|
-
export async function prerender(start, clientDir, logger,
|
|
85
|
+
export async function prerender(start, clientDir, logger, where) {
|
|
86
86
|
const fail = (lines) => {
|
|
87
87
|
for (const line of lines)
|
|
88
88
|
logger.error(`fondu: ${line}`);
|
|
@@ -124,7 +124,7 @@ export async function prerender(start, clientDir, logger, headersFile) {
|
|
|
124
124
|
name,
|
|
125
125
|
/^content-security-policy/i.test(name) ? staticPolicy(value, hashes) : value,
|
|
126
126
|
]));
|
|
127
|
-
if (
|
|
127
|
+
if (security && JSON.stringify(headers) !== JSON.stringify(security)) {
|
|
128
128
|
errors.push(`${path}: its security headers differ from ${paths[0]}'s; one set is written for all`);
|
|
129
129
|
continue;
|
|
130
130
|
}
|
|
@@ -136,7 +136,10 @@ export async function prerender(start, clientDir, logger, headersFile) {
|
|
|
136
136
|
}
|
|
137
137
|
if (errors.length)
|
|
138
138
|
return fail(errors);
|
|
139
|
-
if (
|
|
139
|
+
if ('serverDir' in where) {
|
|
140
|
+
write(where.serverDir, 'prerender.json', JSON.stringify({ headers: security ?? {} }));
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
140
143
|
const file = join(clientDir, '_headers');
|
|
141
144
|
const own = existsSync(file) ? readFileSync(file, 'utf8') : '';
|
|
142
145
|
writeFileSync(file, withHeaderRules(own, security ?? {}));
|
package/dist/vite/strip.d.ts
CHANGED
|
@@ -14,6 +14,6 @@ type Node = {
|
|
|
14
14
|
export declare function stripServerCode(code: string, program: {
|
|
15
15
|
body: Node[];
|
|
16
16
|
}, file: string): string;
|
|
17
|
-
/** The browser's copy of every page's route file (`.tsx
|
|
17
|
+
/** The browser's copy of every page's route file (`.tsx` in `app/routes/`): its server code removed */
|
|
18
18
|
export declare function stripRoutes(): Plugin;
|
|
19
19
|
export {};
|
package/dist/vite/strip.js
CHANGED
|
@@ -272,7 +272,7 @@ function importOf(code, node, kept) {
|
|
|
272
272
|
].filter(Boolean);
|
|
273
273
|
return `import ${clauses.join(', ')} from ${source};`;
|
|
274
274
|
}
|
|
275
|
-
/** The browser's copy of every page's route file (`.tsx
|
|
275
|
+
/** The browser's copy of every page's route file (`.tsx` in `app/routes/`): its server code removed */
|
|
276
276
|
export function stripRoutes() {
|
|
277
277
|
let root = process.cwd();
|
|
278
278
|
return {
|
package/dist/vite/typegen.js
CHANGED
|
@@ -25,7 +25,7 @@ function generateTypes(root) {
|
|
|
25
25
|
declare module 'fondu' {
|
|
26
26
|
interface Register {
|
|
27
27
|
routes: {
|
|
28
|
-
${routes.flatMap((f) => patternsOf(f).map((p) => line(p, `./routes/${f.replace(/\.
|
|
28
|
+
${routes.flatMap((f) => patternsOf(f).map((p) => line(p, `./routes/${f.replace(/\.tsx?$/, '')}`))).join('\n')}
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
}
|