@zubra/server 5.3.0 → 5.4.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zubra/server",
3
- "version": "5.3.0",
3
+ "version": "5.4.1",
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",
@@ -27,8 +27,8 @@
27
27
  "test": "node --test \"test/*.test.js\""
28
28
  },
29
29
  "peerDependencies": {
30
- "@zubra/compiler": "^5.3.0",
31
- "@zubra/runtime": "^5.3.0"
30
+ "@zubra/compiler": "^5.4.0",
31
+ "@zubra/runtime": "^5.4.0"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@minify-html/node": "0.18.1",
package/src/index.d.ts CHANGED
@@ -61,6 +61,11 @@ export interface ZubraOptions {
61
61
  cache?: boolean;
62
62
  /** Serve the runtime's production build, without hot reloading (default: `NODE_ENV` is `production`). */
63
63
  production?: boolean;
64
+ /**
65
+ * Compile for the Zubra DevTools extension and serve the runtime build it reads (default: on,
66
+ * except in production; `ZUBRA_DEVTOOLS=1` turns it on there too).
67
+ */
68
+ devtools?: boolean;
64
69
  }
65
70
 
66
71
  export declare function createZubra(options?: ZubraOptions): Zubra;
package/src/index.js CHANGED
@@ -37,16 +37,19 @@ const TYPES = { '.js': 'text/javascript; charset=utf-8', '.css': 'text/css; char
37
37
  * `components`: the folder of `.zb` (and `.zb.jsx`/`.zb.tsx`) files. `prefix`: the URL path
38
38
  * the browser modules are served under. `cache`: keep compiled output (turn it off in
39
39
  * development to pick up edits). `production`: serve the runtime's production build, without hot
40
- * reloading (by default when `NODE_ENV` is `production`). `imports`: more import map entries,
40
+ * reloading (by default when `NODE_ENV` is `production`). `devtools`: compile for the Zubra DevTools
41
+ * extension and serve the runtime build it reads (on by default except in production;
42
+ * `ZUBRA_DEVTOOLS=1` turns it on there too, for a demo or a staging site). `imports`: more import map entries,
41
43
  * for packages the components import beyond `@zubra/runtime` and `@zubra/sync` (both of which
42
44
  * are served and mapped by themselves).
43
45
  */
44
- export function createZubra({ components = 'components', prefix = '/_zubra', cache = true, production = process.env.NODE_ENV === '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 = {} } = {}) {
45
47
  const root = resolve(components);
46
48
  if (!existsSync(root)) throw new Error(`@zubra/server: no components folder at ${root}`);
47
49
  const sourceDir = dirname(fileURLToPath(import.meta.resolve('@zubra/runtime')));
48
50
  const productionDir = join(sourceDir, '..', 'dist', 'production');
49
- const runtimeDir = production && existsSync(productionDir) ? productionDir : sourceDir;
51
+ // The Zubra DevTools need the runtime's development build, whose hook the production one leaves out.
52
+ const runtimeDir = production && !devtools && existsSync(productionDir) ? productionDir : sourceDir;
50
53
  const base = prefix.replace(/\/$/, '');
51
54
 
52
55
  // @zubra/sync, for components that start with 'use collection': found from the components
@@ -107,7 +110,7 @@ export function createZubra({ components = 'components', prefix = '/_zubra', cac
107
110
  call(pathOf(name), { emit: 'html', props, slots, slotSource: 'html', partial: true, ...(pending.length ? { pending } : {}) });
108
111
  const css = (name) => once(`css:${name}`, () => call(pathOf(name), { emit: 'css' }));
109
112
  const js = (name) => once(`js:${name}`, () => {
110
- const response = need().compileFile(pathOf(name), { emit: 'js', runtime: '@zubra/runtime' });
113
+ const response = need().compileFile(pathOf(name), { emit: 'js', runtime: '@zubra/runtime', devtools });
111
114
  if (!response.ok) throw new Error(response.error);
112
115
  return needs(name, response.output);
113
116
  });