clarusjs 0.13.0 → 0.14.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/dist/check/generate.js +42 -8
- package/dist/compiler/class-style.d.ts +1 -1
- package/dist/compiler/class-style.js +4 -0
- package/dist/compiler/emit-client.js +15 -1
- package/dist/compiler/emit-server.js +11 -4
- package/dist/compiler/html-expr.d.ts +10 -2
- package/dist/compiler/html-expr.js +28 -16
- package/dist/compiler/icon.d.ts +1 -1
- package/dist/compiler/icon.js +4 -0
- package/dist/compiler/index.js +10 -1
- package/dist/compiler/ir.d.ts +19 -0
- package/dist/compiler/ir.js +27 -1
- package/dist/compiler/lint.js +12 -1
- package/dist/compiler/parse.d.ts +24 -0
- package/dist/compiler/parse.js +66 -0
- package/dist/compiler/script.d.ts +10 -1
- package/dist/compiler/script.js +17 -3
- package/dist/fetch/index.d.ts +157 -3
- package/dist/fetch/index.js +135 -14
- package/dist/runtime/dom.d.ts +9 -0
- package/dist/runtime/dom.js +24 -0
- package/dist/runtime/index.d.ts +1 -1
- package/dist/runtime/index.js +1 -1
- package/dist/runtime/server.d.ts +12 -0
- package/dist/runtime/server.js +34 -1
- package/dist/server/handler.d.ts +1 -1
- package/dist/server/handler.js +5 -2
- package/dist/server/views.d.ts +1 -1
- package/dist/server/views.js +1 -1
- package/dist/vite/plugin.js +15 -2
- package/package.json +1 -1
package/dist/server/handler.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { modeFor } from './modes.js';
|
|
2
|
-
import {
|
|
2
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
3
|
+
import { toBrowser } from '../runtime/server.js';
|
|
3
4
|
import { completeHead } from './head.js';
|
|
4
5
|
import { escape } from '../runtime/html.js';
|
|
5
6
|
const DATA = '__data.json';
|
|
6
7
|
const FRAG = 'index.frag.html';
|
|
7
8
|
const safeJson = (json) => json.replace(/</g, '\\u003c');
|
|
9
|
+
const loadedStore = new AsyncLocalStorage();
|
|
10
|
+
globalThis.__clLoadedStore = loadedStore;
|
|
8
11
|
const PARAM = /^\[([A-Za-z_$][\w$]*)\]$/;
|
|
9
12
|
function compile(path) {
|
|
10
13
|
const keys = [];
|
|
@@ -296,7 +299,7 @@ export function createHandler(pages, options = {}) {
|
|
|
296
299
|
let html;
|
|
297
300
|
try {
|
|
298
301
|
const module = await found.route.load();
|
|
299
|
-
html =
|
|
302
|
+
html = await loadedStore.run(componentData, () => module.render(props));
|
|
300
303
|
}
|
|
301
304
|
catch (err) {
|
|
302
305
|
return fail(`${found.route.file}: render failed: ${err?.message ?? err}`, err);
|
package/dist/server/views.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HTML } from '../runtime/html.ts';
|
|
2
2
|
type View = {
|
|
3
|
-
render(props?: object, slots?: Record<string, string>): string
|
|
3
|
+
render(props?: object, slots?: Record<string, string>): string | Promise<string>;
|
|
4
4
|
};
|
|
5
5
|
type Registry = Record<string, () => Promise<View>>;
|
|
6
6
|
/**
|
package/dist/server/views.js
CHANGED
|
@@ -38,7 +38,7 @@ export async function h(name, props = {}, children = []) {
|
|
|
38
38
|
const filled = await Promise.all(entries.map(([, content]) => childrenHtml(content)));
|
|
39
39
|
entries.forEach(([slot], k) => { if (filled[k])
|
|
40
40
|
slots[slot] = filled[k]; });
|
|
41
|
-
return html((await load()).render(props, Object.keys(slots).length ? slots : undefined));
|
|
41
|
+
return html(await (await load()).render(props, Object.keys(slots).length ? slots : undefined));
|
|
42
42
|
}
|
|
43
43
|
const tag = name.toLowerCase();
|
|
44
44
|
if (!/^[a-z][a-z0-9-]*$/.test(tag))
|
package/dist/vite/plugin.js
CHANGED
|
@@ -561,6 +561,8 @@ export default function clarusjs(options = {}) {
|
|
|
561
561
|
transform: {
|
|
562
562
|
filter: { id: fileRe },
|
|
563
563
|
async handler(raw, id) {
|
|
564
|
+
if (/[?&](raw|url|inline)\b/.test(id))
|
|
565
|
+
return null;
|
|
564
566
|
const file = id.replace(/\?.*$/, '');
|
|
565
567
|
const src = sources.find((x) => file.endsWith(x.extension));
|
|
566
568
|
if (src && (/[?&](raw|url|inline)\b/.test(id) || !normalizePath(file).startsWith(normalizePath(resolve(root, 'src/pages')) + '/')))
|
|
@@ -690,9 +692,20 @@ export default function clarusjs(options = {}) {
|
|
|
690
692
|
return void res.writeHead(301, { location: to }).end();
|
|
691
693
|
}
|
|
692
694
|
const app = await env.runner.import(ENTRY);
|
|
693
|
-
|
|
694
|
-
|
|
695
|
+
let response = await app.default.fetch(toRequest(req));
|
|
696
|
+
const html = response.headers.get('content-type')?.startsWith('text/html');
|
|
697
|
+
if (response.status === 404 && !html)
|
|
695
698
|
return next();
|
|
699
|
+
if (html && req.method !== 'HEAD') {
|
|
700
|
+
const text = await response.clone().text();
|
|
701
|
+
const has = /<script\b[^>]*\ssrc=["'][^"']*\/@vite\/client["']/i.test(text);
|
|
702
|
+
if (!has && /<\/head>/i.test(text)) {
|
|
703
|
+
const client = `<script type="module" src="${server.config.base}@vite/client"></script>`;
|
|
704
|
+
const headers = new Headers(response.headers);
|
|
705
|
+
headers.delete('content-length');
|
|
706
|
+
response = new Response(text.replace(/<\/head>/i, `${client}</head>`), { status: response.status, statusText: response.statusText, headers });
|
|
707
|
+
}
|
|
708
|
+
}
|
|
696
709
|
await sendResponse(res, response);
|
|
697
710
|
}
|
|
698
711
|
catch (err) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clarusjs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "Clear, compiled views: templates compiled to server HTML, with JavaScript only for interactive islands. SSR, SSG and CSR from one component model, built on Vite.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|