fondu 0.9.3 → 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/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/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;
|