fondu 0.9.2 → 0.9.4
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/paths.d.ts +4 -1
- package/dist/paths.js +7 -2
- package/dist/server/flash.d.ts +1 -1
- package/dist/server/protocol.d.ts +8 -4
- package/dist/vite/layouts.js +34 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Fondu
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://fondu.dev)
|
|
4
4
|
|
|
5
5
|
Fondu is a small meta-framework for full-stack React apps, built on Hono, Vite and Inertia. It runs on Bun, Cloudflare
|
|
6
6
|
Workers and Node.
|
package/dist/paths.d.ts
CHANGED
|
@@ -11,7 +11,10 @@
|
|
|
11
11
|
export declare function routePatterns(file: string): string[];
|
|
12
12
|
/** a path inside `routes/` that is a route file: every `.ts` file but `_middleware.ts`, tests and declarations */
|
|
13
13
|
export declare function isRouteFile(file: string): boolean;
|
|
14
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* a path inside `pages/` that is a page: a .tsx, .jsx or .mdx file but tests (as for routes), neither its name nor a
|
|
16
|
+
* directory on its path starting with `_` (`_layout.tsx`, `_parts/badge.tsx`)
|
|
17
|
+
*/
|
|
15
18
|
export declare function isPageFile(file: string): boolean;
|
|
16
19
|
/** the directories of `pages/` whose `_layout.tsx` wraps a page, outermost first: `docs/intro.mdx` → `['', 'docs']` */
|
|
17
20
|
export declare function layoutsOf(file: string): string[];
|
package/dist/paths.js
CHANGED
|
@@ -35,9 +35,14 @@ export function isRouteFile(file) {
|
|
|
35
35
|
!/\.(test|spec)\.ts$/.test(file) &&
|
|
36
36
|
file.split('/').at(-1) !== '_middleware.ts');
|
|
37
37
|
}
|
|
38
|
-
/**
|
|
38
|
+
/**
|
|
39
|
+
* a path inside `pages/` that is a page: a .tsx, .jsx or .mdx file but tests (as for routes), neither its name nor a
|
|
40
|
+
* directory on its path starting with `_` (`_layout.tsx`, `_parts/badge.tsx`)
|
|
41
|
+
*/
|
|
39
42
|
export function isPageFile(file) {
|
|
40
|
-
return /\.(?:[jt]sx|mdx)$/.test(file) &&
|
|
43
|
+
return (/\.(?:[jt]sx|mdx)$/.test(file) &&
|
|
44
|
+
!/\.(?:test|spec)\.[jt]sx$/.test(file) &&
|
|
45
|
+
!file.split('/').some((s) => s.startsWith('_')));
|
|
41
46
|
}
|
|
42
47
|
/** the directories of `pages/` whose `_layout.tsx` wraps a page, outermost first: `docs/intro.mdx` → `['', 'docs']` */
|
|
43
48
|
export function layoutsOf(file) {
|
package/dist/server/flash.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { Context, MiddlewareHandler } from 'hono';
|
|
|
3
3
|
/** https, directly or behind a proxy that says so */
|
|
4
4
|
export declare const isSecure: (c: Context) => boolean;
|
|
5
5
|
/** Flash data for the next page (`page.flash` / `usePage().flash`, Inertia's `flash` event). */
|
|
6
|
-
export declare function flash(c: Context, data: Partial<FlashData>
|
|
6
|
+
export declare function flash(c: Context, data: Partial<FlashData>): void;
|
|
7
7
|
/** Validation errors for the next page (its `errors` prop). */
|
|
8
8
|
export declare function flashErrors(c: Context, errors: Record<string, unknown>): void;
|
|
9
9
|
/** The next page clears the browser history Inertia kept (and encrypted): after signing out, for example. */
|
|
@@ -9,17 +9,21 @@ type Shareable<T> = {
|
|
|
9
9
|
[K in keyof T]?: T[K] | (() => T[K] | Promise<T[K]>);
|
|
10
10
|
};
|
|
11
11
|
/** Props every page of this request gets (a middleware calls it: the signed-in user…). */
|
|
12
|
-
export declare function share(c: Context, props: Shareable<SharedPageProps>
|
|
12
|
+
export declare function share(c: Context, props: Shareable<SharedPageProps>): void;
|
|
13
13
|
type PageName = [keyof Pages] extends [never] ? string : Extract<keyof Pages, string>;
|
|
14
14
|
type ComponentProps<N> = N extends keyof Pages ? Pages[N] extends {
|
|
15
15
|
default: (...args: infer A) => unknown;
|
|
16
16
|
} ? A extends [infer P, ...unknown[]] ? P : Record<string, never> : Record<string, unknown> : Record<string, unknown>;
|
|
17
|
+
/** the props a page names: not an index signature (a page without props takes `Record<string, never>`) */
|
|
18
|
+
type Named<P> = keyof {
|
|
19
|
+
[K in keyof P as string extends K ? never : number extends K ? never : K]: 0;
|
|
20
|
+
};
|
|
17
21
|
/** shared props the page takes with the same type: `render` may leave them out (every page gets them) */
|
|
18
22
|
type FromShared<P> = {
|
|
19
|
-
[K in
|
|
20
|
-
}[
|
|
23
|
+
[K in Named<P> & keyof SharedPageProps]: SharedPageProps[K] extends P[K] ? K : never;
|
|
24
|
+
}[Named<P> & keyof SharedPageProps];
|
|
21
25
|
/** a page prop named like a shared prop, of another type: it would hide the shared one from the layout */
|
|
22
|
-
type Clashing<P> = string extends keyof SharedPageProps ? never : Exclude<
|
|
26
|
+
type Clashing<P> = string extends keyof SharedPageProps ? never : Exclude<Named<P> & keyof SharedPageProps, FromShared<P>>;
|
|
23
27
|
type ClashError = 'fondu: this page prop has the name of a shared prop (share()); rename it';
|
|
24
28
|
/** what `render` takes: the component's props, less `errors` and the shared props it gets anyway (may still be given) */
|
|
25
29
|
type OwnProps<N> = Omit<ComponentProps<N>, FromShared<ComponentProps<N>> | Clashing<ComponentProps<N>> | 'errors'> & Partial<Pick<ComponentProps<N>, FromShared<ComponentProps<N>>>> & {
|
package/dist/vite/layouts.js
CHANGED
|
@@ -24,13 +24,15 @@ export function layouts() {
|
|
|
24
24
|
const rel = relative(pagesDir(), file).split(sep).join('/');
|
|
25
25
|
if (rel.startsWith('..') || !isPageFile(rel))
|
|
26
26
|
return;
|
|
27
|
+
const found = defaultExport(this.parse(code), code);
|
|
28
|
+
// a component put in app/pages/ by mistake would be a page, named and typed: an error instead
|
|
29
|
+
if (!found) {
|
|
30
|
+
this.error(`fondu: app/pages/${rel} has no default export. A page is its module's default export; a file in app/pages/ that is not a page goes elsewhere (components/, say), or its name starts with _`);
|
|
31
|
+
}
|
|
27
32
|
const chain = layoutsOf(rel)
|
|
28
33
|
.map(layoutFile)
|
|
29
34
|
.filter((f) => f !== undefined);
|
|
30
|
-
if (!chain.length)
|
|
31
|
-
return;
|
|
32
|
-
const found = defaultExport(this.parse(code), code);
|
|
33
|
-
if (!found)
|
|
35
|
+
if (!chain.length || found.name === undefined)
|
|
34
36
|
return;
|
|
35
37
|
// added at the end (imports are hoisted) and within a line: the lines stay where they were (`map: null`)
|
|
36
38
|
const imports = chain
|
|
@@ -54,17 +56,40 @@ export function layouts() {
|
|
|
54
56
|
},
|
|
55
57
|
};
|
|
56
58
|
}
|
|
59
|
+
const nameOf = (n) => n.name ?? n.value;
|
|
57
60
|
/**
|
|
58
61
|
* The name of the module's default export, to set `layout` on: a named function or class as it is; an anonymous one,
|
|
59
|
-
* or an expression, given a name first (`const __fondu_page = …`, exported at the end)
|
|
62
|
+
* or an expression, given a name first (`const __fondu_page = …`, exported at the end). A component re-exported from
|
|
63
|
+
* another module (`export { default } from './edit.tsx'`) is wrapped in one of this page's own: two pages may share a
|
|
64
|
+
* component under different layouts. `name: undefined`: a default export to leave alone (`export * as default`).
|
|
60
65
|
*/
|
|
61
66
|
function defaultExport(program, code) {
|
|
62
67
|
for (const node of program.body) {
|
|
63
|
-
if (node.type === '
|
|
68
|
+
if (node.type === 'ExportAllDeclaration' && node.exported)
|
|
69
|
+
if (nameOf(node.exported) === 'default')
|
|
70
|
+
return { name: undefined, code };
|
|
71
|
+
if (node.type === 'ExportNamedDeclaration') {
|
|
64
72
|
const specifiers = node.specifiers;
|
|
65
|
-
const specifier = specifiers.find((sp) => sp.exported
|
|
66
|
-
if (specifier)
|
|
67
|
-
|
|
73
|
+
const specifier = specifiers.find((sp) => nameOf(sp.exported) === 'default');
|
|
74
|
+
if (!specifier)
|
|
75
|
+
continue;
|
|
76
|
+
if (!node.source)
|
|
77
|
+
return { name: nameOf(specifier.local), code };
|
|
78
|
+
const source = code.slice(node.source.start, node.source.end);
|
|
79
|
+
const others = specifiers.filter((sp) => sp !== specifier);
|
|
80
|
+
const kept = others.length
|
|
81
|
+
? `export { ${others.map((sp) => code.slice(sp.start, sp.end)).join(', ')} } from ${source};`
|
|
82
|
+
: '';
|
|
83
|
+
const local = nameOf(specifier.local);
|
|
84
|
+
const imported = /^[A-Za-z_$][\w$]*$/.test(local) ? local : JSON.stringify(local);
|
|
85
|
+
return {
|
|
86
|
+
name: '__fondu_page',
|
|
87
|
+
code: `${code.slice(0, node.start)}${kept}${code.slice(node.end)}\n` +
|
|
88
|
+
`import { ${imported} as __fondu_shared } from ${source};\n` +
|
|
89
|
+
`import { createElement as __fondu_h } from 'react';\n` +
|
|
90
|
+
`const __fondu_page = (props) => __fondu_h(__fondu_shared, props);\n` +
|
|
91
|
+
`export default __fondu_page;`,
|
|
92
|
+
};
|
|
68
93
|
}
|
|
69
94
|
if (node.type !== 'ExportDefaultDeclaration')
|
|
70
95
|
continue;
|