@zubra/server 5.5.0 → 5.7.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/package.json +3 -3
- package/src/core.js +10 -3
- package/src/edge.d.ts +2 -0
- package/src/edge.js +2 -1
- package/src/index.d.ts +6 -1
- package/src/index.js +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zubra/server",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.7.0",
|
|
4
4
|
"description": "Zubra on the server: render components into any template engine's pages, serve their browser modules, and give frameworks' HTML its components' shadow roots.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"test": "node --test \"test/*.test.js\""
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@zubra/compiler": "^5.
|
|
39
|
-
"@zubra/runtime": "^5.
|
|
38
|
+
"@zubra/compiler": "^5.7.0",
|
|
39
|
+
"@zubra/runtime": "^5.7.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@minify-html/node": "0.18.1",
|
package/src/core.js
CHANGED
|
@@ -19,7 +19,7 @@ export { SOURCE_EXTENSION, TYPES };
|
|
|
19
19
|
* host serves under `<base>/` beyond the components' modules (`{ status, type, body }` or null).
|
|
20
20
|
* `needs(name, code)`: the host's check on a compiled module (a package it needs being installed).
|
|
21
21
|
*/
|
|
22
|
-
export function createCore({ request, files, sourcesOf: readSources, cache = true, devtools = false, base, imports = {}, syncImports = {}, needs = (_name, code) => code, where = 'the components', assets = () => null }) {
|
|
22
|
+
export function createCore({ request, files, sourcesOf: readSources, cache = true, devtools = false, base, imports = {}, syncImports = {}, needs = (_name, code) => code, where = 'the components', assets = () => null, warn = (message) => console.warn(message) }) {
|
|
23
23
|
const memo = new Map();
|
|
24
24
|
const once = (key, make) => {
|
|
25
25
|
if (!cache || !memo.has(key)) memo.set(key, make());
|
|
@@ -42,8 +42,15 @@ export function createCore({ request, files, sourcesOf: readSources, cache = tru
|
|
|
42
42
|
const byTag = () => once('tags', () => new Map([...files.keys()].map((name) => [describe(name).tag, name])));
|
|
43
43
|
const nameOf = (nameOrTag) => (files.has(nameOrTag) ? nameOrTag : byTag().get(nameOrTag));
|
|
44
44
|
|
|
45
|
-
const render = (name, props = {}, slots = {}, pending = []) =>
|
|
46
|
-
|
|
45
|
+
const render = (name, props = {}, slots = {}, pending = []) => {
|
|
46
|
+
const path = pathOf(name);
|
|
47
|
+
const response = request({ path, files: sourcesOf(path), emit: 'html', props, slots, slotSource: 'html', partial: true, ...(pending.length ? { pending } : {}) });
|
|
48
|
+
if (!response.ok) throw new Error(response.error);
|
|
49
|
+
// A value that isn't a safe URL (a user's `javascript:` link) is left out, as the element
|
|
50
|
+
// leaves it out in the browser; the page still renders, and this says what was dropped.
|
|
51
|
+
for (const message of response.omitted ?? []) warn(`@zubra/server: <${name}>: ${message}`);
|
|
52
|
+
return response.output;
|
|
53
|
+
};
|
|
47
54
|
const css = (name) => once(`css:${name}`, () => call(pathOf(name), { emit: 'css' }));
|
|
48
55
|
const js = (name) => once(`js:${name}`, () => {
|
|
49
56
|
const path = pathOf(name);
|
package/src/edge.d.ts
CHANGED
|
@@ -37,6 +37,8 @@ export interface EdgeOptions {
|
|
|
37
37
|
devtools?: boolean;
|
|
38
38
|
/** More import map entries; use it to point `@zubra/runtime` at a CDN, or at your static assets. */
|
|
39
39
|
imports?: Record<string, string>;
|
|
40
|
+
/** Told when a render leaves out an attribute whose value isn't a safe URL (default `console.warn`). */
|
|
41
|
+
warn?: (message: string) => void;
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
export declare function createZubra(options: EdgeOptions): EdgeZubra;
|
package/src/edge.js
CHANGED
|
@@ -37,7 +37,7 @@ function normalize(path) {
|
|
|
37
37
|
* `cache`, `devtools` (off by default here: the DevTools need the runtime's development build,
|
|
38
38
|
* which you would have to serve yourself) and `imports`.
|
|
39
39
|
*/
|
|
40
|
-
export function createZubra({ wasm, compiler = wasm ? createCompiler(wasm) : null, components = {}, prefix = '/_zubra', cache = true, devtools = false, imports = {} } = {}) {
|
|
40
|
+
export function createZubra({ wasm, compiler = wasm ? createCompiler(wasm) : null, components = {}, prefix = '/_zubra', cache = true, devtools = false, imports = {}, warn } = {}) {
|
|
41
41
|
if (!compiler) throw new Error("@zubra/server/edge: createZubra() needs the compiler's WebAssembly module (`wasm`), or a `compiler` from createCompiler()");
|
|
42
42
|
const sources = new Map(); // path → source
|
|
43
43
|
const files = new Map(); // name → path
|
|
@@ -73,6 +73,7 @@ export function createZubra({ wasm, compiler = wasm ? createCompiler(wasm) : nul
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
return createCore({
|
|
76
|
+
warn,
|
|
76
77
|
request: (body) => compiler.request(body),
|
|
77
78
|
files,
|
|
78
79
|
sourcesOf: (path) => sourcesOf(path),
|
package/src/index.d.ts
CHANGED
|
@@ -4,7 +4,10 @@ export interface ComponentInfo { tag: string; shadow: boolean; form: boolean; pr
|
|
|
4
4
|
export interface Page {
|
|
5
5
|
/** The components this page rendered, in order. */
|
|
6
6
|
readonly used: string[];
|
|
7
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* A component's server-rendered HTML (by its file name, or its tag). `slots` are HTML, kept as
|
|
9
|
+
* written: other components' `render()` output included, so one can be put inside another.
|
|
10
|
+
*/
|
|
8
11
|
render(name: string, props?: Record<string, unknown>, slots?: Record<string, string>): string;
|
|
9
12
|
/** The used components' CSS and the import map, for `<head>`. */
|
|
10
13
|
head(): string;
|
|
@@ -66,6 +69,8 @@ export interface ZubraOptions {
|
|
|
66
69
|
* except in production; `ZUBRA_DEVTOOLS=1` turns it on there too).
|
|
67
70
|
*/
|
|
68
71
|
devtools?: boolean;
|
|
72
|
+
/** Told when a render leaves out an attribute whose value isn't a safe URL (default `console.warn`). */
|
|
73
|
+
warn?: (message: string) => void;
|
|
69
74
|
}
|
|
70
75
|
|
|
71
76
|
export declare function createZubra(options?: ZubraOptions): Zubra;
|
package/src/index.js
CHANGED
|
@@ -43,7 +43,7 @@ const posix = (path) => path.split(sep).join('/');
|
|
|
43
43
|
*
|
|
44
44
|
* Everything that doesn't need a disk is in `core.js`, shared with `edge.js` (Workers).
|
|
45
45
|
*/
|
|
46
|
-
export function createZubra({ components = 'components', prefix = '/_zubra', cache = true, production = process.env.NODE_ENV === 'production', devtools = process.env.ZUBRA_DEVTOOLS === '1' || !production, imports = {} } = {}) {
|
|
46
|
+
export function createZubra({ components = 'components', prefix = '/_zubra', cache = true, production = process.env.NODE_ENV === 'production', devtools = process.env.ZUBRA_DEVTOOLS === '1' || !production, imports = {}, warn } = {}) {
|
|
47
47
|
const root = resolve(components);
|
|
48
48
|
if (!existsSync(root)) throw new Error(`@zubra/server: no components folder at ${root}`);
|
|
49
49
|
const sourceDir = dirname(fileURLToPath(import.meta.resolve('@zubra/runtime')));
|
|
@@ -99,6 +99,7 @@ export function createZubra({ components = 'components', prefix = '/_zubra', cac
|
|
|
99
99
|
};
|
|
100
100
|
|
|
101
101
|
const core = createCore({
|
|
102
|
+
warn,
|
|
102
103
|
request: (body) => compiler.request(body),
|
|
103
104
|
files,
|
|
104
105
|
sourcesOf: (path) => compiler.sources(path),
|